From ab4e8ce1613e9f37c7ab68cde6d2f467309b91e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Fri, 19 Apr 2024 17:35:30 +0100 Subject: [PATCH] IH-553: Optimise SExpr.unescape MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Check for the presence of the escape character before rebuilding the string Signed-off-by: Edwin Török --- ocaml/libs/sexpr/sExpr.ml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ocaml/libs/sexpr/sExpr.ml b/ocaml/libs/sexpr/sExpr.ml index 1a5eb9cf907..ec354e373b1 100644 --- a/ocaml/libs/sexpr/sExpr.ml +++ b/ocaml/libs/sexpr/sExpr.ml @@ -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)