diff options
author | Gabriel Scherer <gabriel.scherer@gmail.com> | 2013-08-04 19:58:07 +0000 |
---|---|---|
committer | Gabriel Scherer <gabriel.scherer@gmail.com> | 2013-08-04 19:58:07 +0000 |
commit | da3011fec235bb5bbecbefc11b247bc28a840195 (patch) | |
tree | 878a5cd419932cf87749aad13f0384b04ec10202 | |
parent | 2c990bacc0f9442cca2ed381877b57b65b25576f (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-- | Changes | 1 | ||||
-rw-r--r-- | stdlib/digest.ml | 6 |
2 files changed, 6 insertions, 1 deletions
@@ -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 |