Skip to content

Commit

Permalink
IH-553: Optimise SExpr.unescape
Browse files Browse the repository at this point in the history
Check for the presence of the escape character before rebuilding the string

Signed-off-by: Edwin Török <[email protected]>
  • Loading branch information
edwintorok committed Apr 19, 2024
1 parent c1b5231 commit ab4e8ce
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ocaml/libs/sexpr/sExpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ let escape s =
s

let unescape s =
let buf = Buffer.create (String.length s) in
unescape_buf buf s ; Buffer.contents buf
if String.contains s '\\' then (
let buf = Buffer.create (String.length s) in
unescape_buf buf s ; Buffer.contents buf
) else
s

let mkstring x = String (unescape x)

Expand Down

0 comments on commit ab4e8ce

Please sign in to comment.