changeset 331:41458a694575

Optimize immediate writes of query results
author Adam Chlipala <adamc@hcoop.net>
date Sat, 13 Sep 2008 10:44:58 -0400
parents f307cdd08d81
children 02d15d81ae9b
files src/cjr_print.sml src/mono_opt.sml src/mono_print.sml
diffstat 3 files changed, 19 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/cjr_print.sml	Sat Sep 13 10:33:30 2008 -0400
+++ b/src/cjr_print.sml	Sat Sep 13 10:44:58 2008 -0400
@@ -745,7 +745,7 @@
         in
             box [string "(uw_begin_region(ctx), ",
                  if wontLeakAnything then
-                     string "uw_begin_regio(ctx), "
+                     string "uw_begin_region(ctx), "
                  else
                      box [],
                  string "({",
--- a/src/mono_opt.sml	Sat Sep 13 10:33:30 2008 -0400
+++ b/src/mono_opt.sml	Sat Sep 13 10:44:58 2008 -0400
@@ -280,6 +280,19 @@
                        {disc = disc,
                         result = (TRecord [], loc)}), loc)
 
+      | EWrite (EQuery {exps, tables, state, query,
+                        initial = (EPrim (Prim.String ""), _),
+                        body = (EStrcat ((EPrim (Prim.String s), _),
+                                         (EStrcat ((ERel 0, _),
+                                                   e'), _)), _)}, loc) =>
+        if CharVector.all Char.isSpace s then
+            EQuery {exps = exps, tables = tables, query = query,
+                    state = (TRecord [], loc),
+                    initial = (ERecord [], loc),
+                    body = (optExp (EWrite e', loc), loc)}
+        else
+            e
+
       | _ => e
 
 and optExp e = #1 (U.Exp.map {typ = typ, exp = exp} e)
--- a/src/mono_print.sml	Sat Sep 13 10:33:30 2008 -0400
+++ b/src/mono_print.sml	Sat Sep 13 10:44:58 2008 -0400
@@ -193,11 +193,11 @@
                               p_typ env t,
                               string ")"]
 
-      | EStrcat (e1, e2) => box [p_exp' true env e1,
-                                 space,
-                                 string "^",
-                                 space,
-                                 p_exp' true env e2]
+      | EStrcat (e1, e2) => parenIf par (box [p_exp' true env e1,
+                                              space,
+                                              string "^",
+                                              space,
+                                              p_exp env e2])
 
       | EWrite e => box [string "write(",
                          p_exp env e,