mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-05 18:20:34 +00:00
sys_util: write_zeros: Make clippy clean
favor `if let` over `match` for destructing a single value. Signed-off-by: Dylan Reid <dgreid@chromium.org> Change-Id: I0c09d7ffc380e84d7413d6fed338d65a60563a8f Reviewed-on: https://chromium-review.googlesource.com/1510069 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Stephen Barber <smbarber@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
parent
6a6a36022b
commit
31c79375da
1 changed files with 6 additions and 7 deletions
|
@ -32,15 +32,14 @@ impl<T: PunchHole + Seek + Write> WriteZeroes for T {
|
|||
fn write_zeroes(&mut self, length: usize) -> io::Result<usize> {
|
||||
// Try to punch a hole first.
|
||||
let offset = self.seek(SeekFrom::Current(0))?;
|
||||
match self.punch_hole(offset, length as u64) {
|
||||
Ok(()) => {
|
||||
// Advance the seek cursor as if we had done a real write().
|
||||
self.seek(SeekFrom::Current(length as i64))?;
|
||||
return Ok(length);
|
||||
}
|
||||
Err(_) => {} // fall back to write()
|
||||
if let Ok(()) = self.punch_hole(offset, length as u64) {
|
||||
// Advance the seek cursor as if we had done a real write().
|
||||
self.seek(SeekFrom::Current(length as i64))?;
|
||||
return Ok(length);
|
||||
}
|
||||
|
||||
// fall back to write()
|
||||
|
||||
// punch_hole() failed; fall back to writing a buffer of zeroes
|
||||
// until we have written up to length.
|
||||
let buf_size = min(length, 0x10000);
|
||||
|
|
Loading…
Reference in a new issue