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 +++++ 1 file changed, 5 insertions(+) (limited to 'src/mono_opt.sml') 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), _), _)]) => -- cgit v1.2.3 From 7639360d7a0111054b68c3fe91bb2558706aaefc Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Wed, 3 Dec 2014 21:21:37 -0500 Subject: MonoOpt: remove concatenation with empty string --- src/mono_opt.sml | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/mono_opt.sml') diff --git a/src/mono_opt.sml b/src/mono_opt.sml index a49d54e1..211b273e 100644 --- a/src/mono_opt.sml +++ b/src/mono_opt.sml @@ -166,6 +166,9 @@ fun exp e = e | EFfiApp ("Basis", "strcat", [(e1, _), (e2, _)]) => exp (EStrcat (e1, e2)) + + | EStrcat (e1, (EPrim (Prim.String (_, "")), _)) => #1 e1 + | EStrcat ((EPrim (Prim.String (_, "")), _), e2) => #1 e2 | EStrcat ((EPrim (Prim.String (Prim.Html, s1)), loc), (EPrim (Prim.String (Prim.Html, s2)), _)) => let -- cgit v1.2.3 From 514bde72c4a3f291221bbb362b9496c020042925 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Thu, 4 Dec 2014 19:54:04 -0500 Subject: Optimizing writes of single characters --- include/urweb/urweb_cpp.h | 2 ++ src/c/urweb.c | 4 ++++ src/mono_opt.sml | 2 ++ 3 files changed, 8 insertions(+) (limited to 'src/mono_opt.sml') diff --git a/include/urweb/urweb_cpp.h b/include/urweb/urweb_cpp.h index 637cddfc..39679dd5 100644 --- a/include/urweb/urweb_cpp.h +++ b/include/urweb/urweb_cpp.h @@ -396,4 +396,6 @@ extern const char uw_begin_xhtml[], uw_begin_html5[]; int uw_remoteSock(struct uw_context *); void uw_set_remoteSock(struct uw_context *, int sock); +void uw_Basis_writec(struct uw_context *, char); + #endif diff --git a/src/c/urweb.c b/src/c/urweb.c index 1f2c8b3c..e2881b05 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -1659,6 +1659,10 @@ void uw_writec(uw_context ctx, char c) { uw_writec_unsafe(ctx, c); } +void uw_Basis_writec(uw_context ctx, char c) { + uw_writec(ctx, c); +} + static void uw_write_unsafe(uw_context ctx, const char* s) { int len = strlen(s); memcpy(ctx->page.front, s, len); diff --git a/src/mono_opt.sml b/src/mono_opt.sml index 211b273e..2d40e0f0 100644 --- a/src/mono_opt.sml +++ b/src/mono_opt.sml @@ -626,6 +626,8 @@ fun exp e = EFfiApp ("Basis", "attrifyChar", [e]) | EFfiApp ("Basis", "attrifyString_w", [((EFfiApp ("Basis", "str1", [e]), _), _)]) => EFfiApp ("Basis", "attrifyChar_w", [e]) + | EWrite (EFfiApp ("Basis", "str1", [e]), _) => + EFfiApp ("Basis", "writec", [e]) | EBinop (_, "+", (EPrim (Prim.Int n1), _), (EPrim (Prim.Int n2), _)) => EPrim (Prim.Int (Int64.+ (n1, n2))) -- cgit v1.2.3