# HG changeset patch # User Vladimir Shabanov # Date 1337204490 -14400 # Node ID e8c668e518fb18cf16aacd880244220daac7f353 # Parent 22858505bb2d0b5bd831b6ace787adb3b00e9b23 Speed up space eating in MonoOpt diff -r 22858505bb2d -r e8c668e518fb src/mono_opt.sml --- a/src/mono_opt.sml Wed May 16 22:46:35 2012 +0400 +++ b/src/mono_opt.sml Thu May 17 01:41:30 2012 +0400 @@ -143,21 +143,24 @@ fun exp e = case e of EPrim (Prim.String s) => - let - val (_, chs) = - CharVector.foldl (fn (ch, (lastSpace, chs)) => - let - val isSpace = Char.isSpace ch - in - if isSpace andalso lastSpace then - (true, chs) - else - (isSpace, ch :: chs) - end) - (false, []) s - in - EPrim (Prim.String (String.implode (rev chs))) - end + if CharVector.exists Char.isSpace s then + let + val (_, chs) = + CharVector.foldl (fn (ch, (lastSpace, chs)) => + let + val isSpace = Char.isSpace ch + in + if isSpace andalso lastSpace then + (true, chs) + else + (isSpace, ch :: chs) + end) + (false, []) s + in + EPrim (Prim.String (String.implode (rev chs))) + end + else + e | EFfiApp ("Basis", "strcat", [(e1, _), (e2, _)]) => exp (EStrcat (e1, e2))