Avoid over allocations & reallocations
As we know, vectors amortize the cost of adding new elements by reserving space for multiple elements when full. This is useful but may lead to allocating more memory than necessary. `relibc` generally avoids over allocations by reserving the exact amount of space when possible. I fixed a few areas that still over allocated or reallocated unnecessarily by leveraging iterators that are more likely to know sizes.
This commit is contained in:
@@ -219,10 +219,7 @@ impl Pal for Sys {
|
||||
}
|
||||
|
||||
fn fpath(fildes: c_int, out: &mut [u8]) -> Result<usize> {
|
||||
let mut proc_path = b"/proc/self/fd/".to_vec();
|
||||
write!(proc_path, "{}", fildes).unwrap();
|
||||
proc_path.push(0);
|
||||
|
||||
let proc_path = format!("/proc/self/fd/{}\0", fildes).into_bytes();
|
||||
Self::readlink(CStr::from_bytes_with_nul(&proc_path).unwrap(), out)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user