Hoist out skip_whitespace branching in count_hex_chars

This commit is contained in:
Reynir Björnsson 2024-03-14 13:20:27 +01:00
parent c8aa22f0bb
commit 0898b70e97

10
ohex.ml
View file

@ -9,12 +9,12 @@ let is_space = function
| _ -> false | _ -> false
let count_hex_chars ?(skip_whitespace = true) src = let count_hex_chars ?(skip_whitespace = true) src =
string_fold (fun r c -> if skip_whitespace then
if skip_whitespace && is_space c then string_fold (fun r c ->
r if is_space c then r else succ r)
else
succ r)
0 src / 2 0 src / 2
else
String.length src / 2
let decode_into ?(skip_whitespace = true) src tgt ?(off = 0) () = let decode_into ?(skip_whitespace = true) src tgt ?(off = 0) () =
let fold f acc str = let fold f acc str =