From 3eb676c55c1a031de3019ef497ec4b49fdc86d33 Mon Sep 17 00:00:00 2001 From: Fardale Date: Wed, 19 May 2021 23:36:00 +0200 Subject: [PATCH] replace for loop and unsafe_get by using iter --- src/core/CCHash.ml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/CCHash.ml b/src/core/CCHash.ml index ea6e6341..45cc9621 100644 --- a/src/core/CCHash.ml +++ b/src/core/CCHash.ml @@ -88,12 +88,13 @@ let nativeint (x:nativeint) = Hashtbl.hash x let bytes (x:bytes) = let h = ref fnv_offset_basis in - for i = 0 to Bytes.length x - 1 do - h := Int64.(mul !h fnv_prime); - let byte = Char.code (Bytes.unsafe_get x i) in - h := Int64.(logxor !h (of_int byte)); - done; + Bytes.iter (fun c -> + h := Int64.(mul !h fnv_prime); + let byte = Char.code c in + h := Int64.(logxor !h (of_int byte)); + ) x; Int64.to_int !h land max_int + let string (x:string) = bytes (Bytes.unsafe_of_string x) (*$T