Browse Source

[jvm] fixed compile-time hashing of unicode strings

Aleksandr Kuzmenko 5 years ago
parent
commit
2115942cfc
1 changed files with 6 additions and 4 deletions
  1. 6 4
      src/generators/genjvm.ml

+ 6 - 4
src/generators/genjvm.ml

@@ -43,11 +43,13 @@ let rec pow a b = match b with
 
 
 let java_hash s =
 let java_hash s =
 	let h = ref Int32.zero in
 	let h = ref Int32.zero in
-	let l = String.length s in
+	let l = UTF8.length s in
 	let i31 = Int32.of_int 31 in
 	let i31 = Int32.of_int 31 in
-	String.iteri (fun i char ->
-		let char = Int32.of_int (int_of_char char) in
-		h := Int32.add !h (Int32.mul char (pow i31 (l - (i + 1))))
+	let i = ref 0 in
+	UTF8.iter (fun char ->
+		let char = Int32.of_int (UCharExt.uint_code char) in
+		h := Int32.add !h (Int32.mul char (pow i31 (l - (!i + 1))));
+		incr i;
 	) s;
 	) s;
 	!h
 	!h