Skip to content

Commit fee5aa7

Browse files
committed
Drop intermediate buf in fread_refcount
1 parent a4a53d3 commit fee5aa7

1 file changed

Lines changed: 2 additions & 19 deletions

File tree

‎libcc2rs/src/io.rs‎

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,8 @@ pub fn fread_refcount(a0: AnyPtr, a1: usize, a2: usize, a3: Ptr<CFile>) -> usize
107107
if total == 0 {
108108
return 0;
109109
}
110-
let mut dst = a0.reinterpret_cast::<u8>();
111-
let mut buffer: [u8; 8192] = [0; 8192];
112-
let mut read_bytes: usize = 0;
113-
114-
a3.with_mut(|f| {
115-
while read_bytes < total {
116-
let to_read = std::cmp::min(buffer.len(), total - read_bytes);
117-
let n = f.read(&mut buffer[..to_read]);
118-
if n == 0 {
119-
break;
120-
}
121-
for &byte in &buffer[..n] {
122-
dst.write(byte);
123-
dst += 1;
124-
}
125-
read_bytes += n;
126-
}
127-
});
128-
110+
let dst = a0.reinterpret_cast::<u8>();
111+
let read_bytes = dst.with_slice_mut(total, |buf| a3.with_mut(|f| f.read(buf)));
129112
read_bytes / a1
130113
}
131114

0 commit comments

Comments
 (0)