Skip to content

Commit

Permalink
Remove now-unnecessary unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Oct 29, 2021
1 parent bb4c687 commit 455c1a6
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions parquet/src/util/hash_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ pub fn hash<T: AsBytes>(data: &T, seed: u32) -> u32 {

fn hash_(data: &[u8], seed: u32) -> u32 {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
unsafe {
{
if is_x86_feature_detected!("sse4.2") {
crc32_hash(data, seed)
unsafe { crc32_hash(data, seed) }
} else {
murmur_hash2_64a(data, seed as u64) as u32
}
Expand All @@ -39,7 +39,7 @@ fn hash_(data: &[u8], seed: u32) -> u32 {
target_arch = "riscv64",
target_arch = "wasm32"
))]
unsafe {
{
murmur_hash2_64a(data, seed as u64) as u32
}
}
Expand All @@ -48,9 +48,7 @@ const MURMUR_PRIME: u64 = 0xc6a4a7935bd1e995;
const MURMUR_R: i32 = 47;

/// Rust implementation of MurmurHash2, 64-bit version for 64-bit platforms
///
/// SAFTETY Only safe on platforms which support unaligned loads (like x86_64)
unsafe fn murmur_hash2_64a(data_bytes: &[u8], seed: u64) -> u64 {
fn murmur_hash2_64a(data_bytes: &[u8], seed: u64) -> u64 {
use std::convert::TryInto;
let len = data_bytes.len();
let len_64 = (len / 8) * 8;
Expand Down Expand Up @@ -145,16 +143,14 @@ mod tests {

#[test]
fn test_murmur2_64a() {
unsafe {
let result = murmur_hash2_64a(b"hello", 123);
assert_eq!(result, 2597646618390559622);
let result = murmur_hash2_64a(b"hello", 123);
assert_eq!(result, 2597646618390559622);

let result = murmur_hash2_64a(b"helloworld", 123);
assert_eq!(result, 4934371746140206573);
let result = murmur_hash2_64a(b"helloworld", 123);
assert_eq!(result, 4934371746140206573);

let result = murmur_hash2_64a(b"helloworldparquet", 123);
assert_eq!(result, 2392198230801491746);
}
let result = murmur_hash2_64a(b"helloworldparquet", 123);
assert_eq!(result, 2392198230801491746);
}

#[test]
Expand Down

0 comments on commit 455c1a6

Please sign in to comment.