1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-04 15:07:47 +00:00

refactor ~ remove unneeded mem::uninitialized() code

.# [why]

`mem::ununitialized()` is deprecated as of rust v1.39.0.

And this use is likely a premature optimization attempting to avoid
initializing the byte array to 0, which is usually a *very* fast operation.

* ref: <https://github.com/rust-lang/rust/blob/master/RELEASES.md>
* ref: <https://stackoverflow.com/questions/3654905/faster-way-to-zero-memory-than-with-memset>
This commit is contained in:
Roy Ivy III 2019-12-22 17:50:40 -06:00
parent b3846bf8f1
commit c969becbf8

View file

@ -14,8 +14,6 @@ extern crate uucore;
use std::fs::File;
use std::io::{self, stdin, BufReader, Read};
#[cfg(not(windows))]
use std::mem;
use std::path::Path;
include!(concat!(env!("OUT_DIR"), "/crc_table.rs"));
@ -39,16 +37,10 @@ fn crc_final(mut crc: u32, mut length: usize) -> u32 {
!crc
}
#[cfg(windows)]
fn init_byte_array() -> Vec<u8> {
vec![0; 1024 * 1024]
}
#[cfg(not(windows))]
fn init_byte_array() -> [u8; 1024 * 1024] {
unsafe { mem::uninitialized() }
}
#[inline]
fn cksum(fname: &str) -> io::Result<(u32, usize)> {
let mut crc = 0u32;