diff options
author | Arseniy Kucher <orsen.kucher@gmail.com> | 2020-10-17 17:32:46 +0300 |
---|---|---|
committer | Andrew Eikum <aeikum@codeweavers.com> | 2020-10-19 21:52:04 +0300 |
commit | 370dc01d07eba692e6d19ceebc7b9e0da07ad0c2 (patch) | |
tree | a03cb6e8454fef001509d9be34fffa942aa70894 | |
parent | a2ccc70f7b0ec522e02cd04e195cd7f574ff90a2 (diff) |
media-converter: Simplify array copy
-rw-r--r-- | media-converter/src/videoconv.rs | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/media-converter/src/videoconv.rs b/media-converter/src/videoconv.rs index ad0137f6..f63f3180 100644 --- a/media-converter/src/videoconv.rs +++ b/media-converter/src/videoconv.rs @@ -213,14 +213,7 @@ impl<'a> Read for PadReader<'a> { return Ok(0); } - if to_copy == out.len() { - out.copy_from_slice(&self.chunk[self.chunk_offs..(self.chunk_offs + to_copy)]); - }else{ - /* FIXME: there's probably some cool functional way to do this */ - for i in 0..to_copy { - out[i] = self.chunk[self.chunk_offs + i]; - } - } + out[..to_copy].copy_from_slice(&self.chunk[self.chunk_offs..(self.chunk_offs + to_copy)]); self.chunk_offs += to_copy; @@ -288,18 +281,11 @@ impl VideoConvState { None => { let blank = include_bytes!("../blank.ogv"); - let remaining = blank.len() - offs; + let to_copy = std::cmp::min(blank.len() - offs, out.len()); - if out.len() <= remaining { - out.copy_from_slice(&blank[offs..(offs + out.len())]); - Ok(out.len()) - }else{ - /* FIXME: there's probably some cool functional way to do this */ - for i in 0..remaining { - out[i] = blank[offs + i]; - } - Ok(remaining) - } + out[..to_copy].copy_from_slice(&blank[offs..(offs + to_copy)]); + + Ok(to_copy) }, } } |