summaryrefslogtreecommitdiff
path: root/stdlib/string.ml
diff options
context:
space:
mode:
authorNicolás Ojeda Bär <n.oje.bar@gmail.com>2018-02-28 09:12:50 +0100
committerNicolás Ojeda Bär <n.oje.bar@gmail.com>2018-02-28 09:12:50 +0100
commit3cfb0bfe6fd48b4479bf85f06051c73d55c8193c (patch)
tree9f7b2b4dbbcead3d9e640ced35c49241489d1018 /stdlib/string.ml
parente92ed4e5437e3e21ea3cdd4d8d1bb50a8f71e575 (diff)
downloadocaml-3cfb0bfe6fd48b4479bf85f06051c73d55c8193c.tar.gz
Avoid branch in String.escaped
Diffstat (limited to 'stdlib/string.ml')
-rw-r--r--stdlib/string.ml13
1 files changed, 5 insertions, 8 deletions
diff --git a/stdlib/string.ml b/stdlib/string.ml
index 74b8a517d3..ffecee90cc 100644
--- a/stdlib/string.ml
+++ b/stdlib/string.ml
@@ -100,17 +100,14 @@ let trim s =
then bts (B.trim (bos s))
else s
-let rec needs_escape s n i =
- if i >= n then false else
+let rec escape s n i =
+ if i >= n then s else
match unsafe_get s i with
- | '\"' | '\\' | '\000'..'\031' | '\127'.. '\255' -> true
- | _ -> needs_escape s n (i+1)
+ | '\"' | '\\' | '\000'..'\031' | '\127'.. '\255' -> bts (B.escaped (bos s))
+ | _ -> escape s n (i+1)
let escaped s =
- if needs_escape s (length s) 0 then
- bts (B.escaped (bos s))
- else
- s
+ escape s (length s) 0
(* duplicated in bytes.ml *)
let rec index_rec s lim i c =