From c881c3b462801bc67419783c4169302fce5e3aeb Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Wed, 3 Dec 2014 21:06:15 -0500 Subject: Some more optimization of string expressions showing up in JSON generation (Meta library) --- src/mono_opt.sml | 5 +++++ src/mono_reduce.sml | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/mono_opt.sml b/src/mono_opt.sml index d1e5ce55..a49d54e1 100644 --- a/src/mono_opt.sml +++ b/src/mono_opt.sml @@ -220,6 +220,11 @@ fun exp e = | EWrite (EFfiApp ("Basis", "htmlifySpecialChar", [e]), _) => EFfiApp ("Basis", "htmlifySpecialChar_w", [e]) + | EWrite (EFfiApp ("Basis", "intToString", [e]), _) => + EFfiApp ("Basis", "htmlifyInt_w", [e]) + | EApp ((EFfi ("Basis", "intToString"), loc), e) => + EFfiApp ("Basis", "intToString", [(e, (TFfi ("Basis", "int"), loc))]) + | EFfiApp ("Basis", "htmlifyString", [((EFfiApp ("Basis", "intToString", [((EPrim (Prim.Int n), _), _)]), _), _)]) => EPrim (Prim.String (Prim.Html, htmlifyInt n)) | EFfiApp ("Basis", "htmlifyString", [((EFfiApp ("Basis", "intToString", es), _), _)]) => diff --git a/src/mono_reduce.sml b/src/mono_reduce.sml index 50553560..591d4c1b 100644 --- a/src/mono_reduce.sml +++ b/src/mono_reduce.sml @@ -208,6 +208,20 @@ fun match (env, p : pat, e : exp) = else No + | (PPrim (Prim.String (_, s)), _) => + let + fun lengthLb (e : exp) = + case #1 e of + EStrcat (e1, e2) => lengthLb e1 + lengthLb e2 + | EPrim (Prim.String (_, s)) => size s + | _ => 0 + in + if lengthLb e > size s then + No + else + Maybe + end + | (PCon (_, PConVar n1, po), ECon (_, PConVar n2, eo)) => if n1 = n2 then case (po, eo) of -- cgit v1.2.3