Skip to content

Commit 40f7f65

Browse files
committed
Make clippy happy
Acutally, we just allow globally clippy::many_single_char_names and clippy::blocks_in_if_conditions. The latter is to be enabled because of clippy bug: rust-lang/rust-clippy#7580 The single char names stem from the original sources, and I prefer to keep them as is.
1 parent 28f526c commit 40f7f65

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

src/lib.rs

+34-32
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ This crate has only single feature used exclusively for benchmarking.
3232
C++ implementations.
3333
*/
3434
#![no_std]
35-
35+
#![allow(clippy::many_single_char_names)]
36+
// This is a false positive: https://github.com/rust-lang/rust-clippy/issues/7580 :
37+
#![allow(clippy::blocks_in_if_conditions)]
3638
use core::num::Wrapping;
3739

38-
type w64 = Wrapping<u64>;
39-
type w32 = Wrapping<u32>;
40+
type W64 = Wrapping<u64>;
41+
type W32 = Wrapping<u32>;
4042

4143
/** C++ CityHash-compatible uint128 type. Please note that From<u128>
4244
* and Into<u128> are defined for this type.
@@ -52,7 +54,7 @@ impl U128 {
5254
Self { lo, hi }
5355
}
5456

55-
const fn from_w64(lo: w64, hi: w64) -> Self {
57+
const fn from_w64(lo: W64, hi: W64) -> Self {
5658
Self { lo: lo.0, hi: hi.0 }
5759
}
5860
}
@@ -72,55 +74,55 @@ impl From<U128> for u128 {
7274
}
7375
}
7476

75-
const fn w64(v: u64) -> w64 {
77+
const fn w64(v: u64) -> W64 {
7678
Wrapping(v)
7779
}
7880

79-
const fn w32(v: u32) -> w32 {
81+
const fn w32(v: u32) -> W32 {
8082
Wrapping(v)
8183
}
8284

8385
// Some primes between 2^63 and 2^64 for various uses.
84-
const K0: w64 = w64(0xc3a5c85c97cb3127u64);
85-
const K1: w64 = w64(0xb492b66fbe98f273u64);
86-
const K2: w64 = w64(0x9ae16a3b2f90404fu64);
87-
const K3: w64 = w64(0xc949d7c7509e6557u64);
86+
const K0: W64 = w64(0xc3a5c85c97cb3127u64);
87+
const K1: W64 = w64(0xb492b66fbe98f273u64);
88+
const K2: W64 = w64(0x9ae16a3b2f90404fu64);
89+
const K3: W64 = w64(0xc949d7c7509e6557u64);
8890

8991
#[inline]
90-
unsafe fn fetch64(s: *const u8) -> w64 {
92+
unsafe fn fetch64(s: *const u8) -> W64 {
9193
w64((s as *const u64).read_unaligned().to_le())
9294
}
9395

9496
#[inline]
95-
unsafe fn fetch32(s: *const u8) -> w32 {
97+
unsafe fn fetch32(s: *const u8) -> W32 {
9698
w32((s as *const u32).read_unaligned().to_le())
9799
}
98100

99101
#[inline]
100-
fn rotate(v: w64, n: u32) -> w64 {
102+
fn rotate(v: W64, n: u32) -> W64 {
101103
debug_assert!(n > 0);
102104
// Look, ma, I have real rotate!
103105
// rotate_right for Wrapping is yet unstable, so we unwrap and wrap it back.
104106
w64(v.0.rotate_right(n))
105107
}
106108

107-
fn hash_len16(u: w64, v: w64) -> w64 {
109+
fn hash_len16(u: W64, v: W64) -> W64 {
108110
hash128_to_64(u, v)
109111
}
110112

111113
// Hash 128 input bits down to 64 bits of output.
112114
// This is intended to be a reasonably good hash function.
113115
#[inline]
114-
fn hash128_to_64(l: w64, h: w64) -> w64 {
115-
const K_MUL: w64 = w64(0x9ddfea08eb382d69u64);
116+
fn hash128_to_64(l: W64, h: W64) -> W64 {
117+
const K_MUL: W64 = w64(0x9ddfea08eb382d69u64);
116118
let mut a = (h ^ l) * K_MUL;
117119
a ^= a >> 47;
118120
let mut b = (h ^ a) * K_MUL;
119121
b ^= b >> 47;
120122
b * K_MUL
121123
}
122124

123-
unsafe fn hash_len0to16(data: &[u8]) -> w64 {
125+
unsafe fn hash_len0to16(data: &[u8]) -> W64 {
124126
let len = data.len();
125127
let s = data.as_ptr();
126128

@@ -148,7 +150,7 @@ unsafe fn hash_len0to16(data: &[u8]) -> w64 {
148150
}
149151
}
150152

151-
unsafe fn hash_len17to32(data: &[u8]) -> w64 {
153+
unsafe fn hash_len17to32(data: &[u8]) -> W64 {
152154
let s = data.as_ptr();
153155
let len = data.len();
154156

@@ -162,7 +164,7 @@ unsafe fn hash_len17to32(data: &[u8]) -> w64 {
162164
)
163165
}
164166

165-
unsafe fn hash_len33to64(data: &[u8]) -> w64 {
167+
unsafe fn hash_len33to64(data: &[u8]) -> W64 {
166168
let s = data.as_ptr();
167169
let len = data.len();
168170

@@ -189,7 +191,7 @@ unsafe fn hash_len33to64(data: &[u8]) -> w64 {
189191
shift_mix(vs + r * K0) * K2
190192
}
191193

192-
unsafe fn weak_hash_len32_with_seeds(s: *const u8, a: w64, b: w64) -> (w64, w64) {
194+
unsafe fn weak_hash_len32_with_seeds(s: *const u8, a: W64, b: W64) -> (W64, W64) {
193195
weak_hash_len32_with_seeds_(
194196
fetch64(s),
195197
fetch64(s.add(8)),
@@ -201,13 +203,13 @@ unsafe fn weak_hash_len32_with_seeds(s: *const u8, a: w64, b: w64) -> (w64, w64)
201203
}
202204

203205
unsafe fn weak_hash_len32_with_seeds_(
204-
w: w64,
205-
x: w64,
206-
y: w64,
207-
z: w64,
208-
mut a: w64,
209-
mut b: w64,
210-
) -> (w64, w64) {
206+
w: W64,
207+
x: W64,
208+
y: W64,
209+
z: W64,
210+
mut a: W64,
211+
mut b: W64,
212+
) -> (W64, W64) {
211213
a += w;
212214
b = rotate(b + a + z, 21);
213215
let c = a;
@@ -216,7 +218,7 @@ unsafe fn weak_hash_len32_with_seeds_(
216218
(a + z, b + c)
217219
}
218220

219-
fn shift_mix(val: w64) -> w64 {
221+
fn shift_mix(val: W64) -> W64 {
220222
val ^ (val >> 47)
221223
}
222224

@@ -244,8 +246,8 @@ pub fn cityhash64(data: &[u8]) -> u64 {
244246
let mut y = fetch64(s.add(len).sub(16)) ^ K1;
245247
let mut z = fetch64(s.add(len).sub(56)) ^ K0;
246248

247-
let mut v: (w64, w64) = weak_hash_len32_with_seeds(s.add(len).sub(64), w64(len as u64), y);
248-
let mut w: (w64, w64) =
249+
let mut v: (W64, W64) = weak_hash_len32_with_seeds(s.add(len).sub(64), w64(len as u64), y);
250+
let mut w: (W64, W64) =
249251
weak_hash_len32_with_seeds(s.add(len).sub(32), K1 * w64(len as u64), K0);
250252

251253
z += shift_mix(v.1) * K1;
@@ -284,8 +286,8 @@ unsafe fn city_murmur(data: &[u8], seed: U128) -> U128 {
284286

285287
let mut a = w64(seed.lo);
286288
let mut b = w64(seed.hi);
287-
let mut c: w64;
288-
let mut d: w64;
289+
let mut c: W64;
290+
let mut d: W64;
289291
let mut l = (len as isize) - 16;
290292

291293
if l <= 0 {

0 commit comments

Comments
 (0)