minor optimizations

This commit is contained in:
yggverse 2025-02-03 13:05:37 +02:00
parent 998a4e97b4
commit c9d5e5987c

View file

@ -40,19 +40,12 @@ pub fn move_all_from_stream_async(
memory_input_stream: MemoryInputStream, memory_input_stream: MemoryInputStream,
cancellable: Cancellable, cancellable: Cancellable,
priority: Priority, priority: Priority,
bytes: ( (bytes_in_chunk, bytes_total_limit, mut bytes_total): (usize, usize, usize),
usize, // bytes_in_chunk (on_chunk, on_complete): (
usize, // bytes_total_limit impl Fn(Bytes, usize) + 'static,
usize, // bytes_total impl FnOnce(Result<(MemoryInputStream, usize), Error>) + 'static,
),
callback: (
impl Fn(Bytes, usize) + 'static, // on_chunk
impl FnOnce(Result<(MemoryInputStream, usize), Error>) + 'static, // on_complete
), ),
) { ) {
let (on_chunk, on_complete) = callback;
let (bytes_in_chunk, bytes_total_limit, bytes_total) = bytes;
base_io_stream.input_stream().read_bytes_async( base_io_stream.input_stream().read_bytes_async(
bytes_in_chunk, bytes_in_chunk,
priority, priority,
@ -60,7 +53,7 @@ pub fn move_all_from_stream_async(
move |result| match result { move |result| match result {
Ok(bytes) => { Ok(bytes) => {
// Update bytes total // Update bytes total
let bytes_total = bytes_total + bytes.len(); bytes_total += bytes.len();
// Callback chunk function // Callback chunk function
on_chunk(bytes.clone(), bytes_total); on_chunk(bytes.clone(), bytes_total);
@ -92,5 +85,5 @@ pub fn move_all_from_stream_async(
on_complete(Err(Error::InputStream(e))); on_complete(Err(Error::InputStream(e)));
} }
}, },
); )
} }