Deduplicate memcpy, memmove, memset and memcmp functions
Created by: jaje
Since core::mem::size_of
is constant function there is no need for them to be duplicated.
Merge request reports
Activity
125 58 i -= 1; 126 59 *((dest as usize + i) as *mut u8) = 127 60 *((src as usize + i) as *const u8); 128 61 } 129 62 } else { 130 let n_32: usize = n/4; // Number of 32-bit groups 63 let n_usize: usize = n/WORD_SIZE; // Number of word sized groups 131 64 let mut i: usize = 0; 132 65 133 // Copy 4 bytes at a time 134 while i < n_32 { 135 *((dest as usize + i) as *mut u32) = 136 *((src as usize + i) as *const u32); 137 i += 4; 66 // Copy `WORD_SIZE` bytes at a time 67 while i < n_usize { Created by: le-jzr
I think this (and similar sites in the rest of the file) should be
i + WORD_SIZE <= n
. The way it is now, you are copying only a fraction of the length here, and copy a byte at a time for almost all of it. (This is not a regression, it was like that in the original code too.)
125 58 i -= 1; 126 59 *((dest as usize + i) as *mut u8) = 127 60 *((src as usize + i) as *const u8); 128 61 } 129 62 } else { 130 let n_32: usize = n/4; // Number of 32-bit groups 63 let n_usize: usize = n/WORD_SIZE; // Number of word sized groups 131 64 let mut i: usize = 0; 132 65 133 // Copy 4 bytes at a time 134 while i < n_32 { 135 *((dest as usize + i) as *mut u32) = 136 *((src as usize + i) as *const u32); 137 i += 4; 66 // Copy `WORD_SIZE` bytes at a time 67 while i < n_usize { 125 58 i -= 1; 126 59 *((dest as usize + i) as *mut u8) = 127 60 *((src as usize + i) as *const u8); 128 61 } 129 62 } else { 130 let n_32: usize = n/4; // Number of 32-bit groups 63 let n_usize: usize = n/WORD_SIZE; // Number of word sized groups 131 64 let mut i: usize = 0; 132 65 133 // Copy 4 bytes at a time 134 while i < n_32 { 135 *((dest as usize + i) as *mut u32) = 136 *((src as usize + i) as *const u32); 137 i += 4; 66 // Copy `WORD_SIZE` bytes at a time 67 while i < n_usize {
Please register or sign in to reply