summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Scherer <gabriel.scherer@gmail.com>2013-08-04 19:58:07 +0000
committerGabriel Scherer <gabriel.scherer@gmail.com>2013-08-04 19:58:07 +0000
commitda3011fec235bb5bbecbefc11b247bc28a840195 (patch)
tree878a5cd419932cf87749aad13f0384b04ec10202
parent2c990bacc0f9442cca2ed381877b57b65b25576f (diff)
PR#6116: more efficient implementation of Digest.to_hex [patch by ygrek]
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13971 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--Changes1
-rw-r--r--stdlib/digest.ml6
2 files changed, 6 insertions, 1 deletions
diff --git a/Changes b/Changes
index cb9a9a821..4d2b49240 100644
--- a/Changes
+++ b/Changes
@@ -9,6 +9,7 @@ Compilers:
Bug fixes:
- PR#4719: Sys.executable_name wrong if executable name contains dots (Windows)
- PR#5201: ocamlbuild: add --norc to the bash invocation to help performances
+- PR#6116: more efficient implementation of Digest.to_hex (patch by ygrek)
Standard library:
- PR#4986: add List.sort_uniq and Set.of_list
diff --git a/stdlib/digest.ml b/stdlib/digest.ml
index aee6cd26c..2baf3dbfa 100644
--- a/stdlib/digest.ml
+++ b/stdlib/digest.ml
@@ -42,10 +42,14 @@ let input chan =
really_input chan digest 0 16;
digest
+let char_hex n = Char.unsafe_chr (n + if n < 10 then Char.code '0' else (Char.code 'a' - 10))
+
let to_hex d =
let result = String.create 32 in
for i = 0 to 15 do
- String.blit (Printf.sprintf "%02x" (int_of_char d.[i])) 0 result (2*i) 2;
+ let x = Char.code d.[i] in
+ String.unsafe_set result (i*2) (char_hex (x lsr 4));
+ String.unsafe_set result (i*2+1) (char_hex (x land 0x0f));
done;
result