changeset 2082:1b76ae703cbb

Some more optimization of string expressions showing up in JSON generation (Meta library)
author Adam Chlipala <adam@chlipala.net>
date Wed, 03 Dec 2014 21:06:15 -0500 (2014-12-04)
parents d4ed20beb93b
children 9f65e2188d3c
files src/mono_opt.sml src/mono_reduce.sml
diffstat 2 files changed, 19 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/mono_opt.sml	Tue Nov 25 08:21:09 2014 -0500
+++ b/src/mono_opt.sml	Wed Dec 03 21:06:15 2014 -0500
@@ -220,6 +220,11 @@
       | 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), _), _)]) =>
--- a/src/mono_reduce.sml	Tue Nov 25 08:21:09 2014 -0500
+++ b/src/mono_reduce.sml	Wed Dec 03 21:06:15 2014 -0500
@@ -208,6 +208,20 @@
         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