comparison src/mono_opt.sml @ 1764:e8c668e518fb

Speed up space eating in MonoOpt
author Vladimir Shabanov <vshabanoff@gmail.com>
date Thu, 17 May 2012 01:41:30 +0400
parents e9587120831a
children 3d922a28370b
comparison
equal deleted inserted replaced
1763:22858505bb2d 1764:e8c668e518fb
141 andalso CharVector.all (fn ch => Char.isLower ch orelse Char.isDigit ch orelse ch = #"_" orelse ch = #"-") s 141 andalso CharVector.all (fn ch => Char.isLower ch orelse Char.isDigit ch orelse ch = #"_" orelse ch = #"-") s
142 142
143 fun exp e = 143 fun exp e =
144 case e of 144 case e of
145 EPrim (Prim.String s) => 145 EPrim (Prim.String s) =>
146 let 146 if CharVector.exists Char.isSpace s then
147 val (_, chs) = 147 let
148 CharVector.foldl (fn (ch, (lastSpace, chs)) => 148 val (_, chs) =
149 let 149 CharVector.foldl (fn (ch, (lastSpace, chs)) =>
150 val isSpace = Char.isSpace ch 150 let
151 in 151 val isSpace = Char.isSpace ch
152 if isSpace andalso lastSpace then 152 in
153 (true, chs) 153 if isSpace andalso lastSpace then
154 else 154 (true, chs)
155 (isSpace, ch :: chs) 155 else
156 end) 156 (isSpace, ch :: chs)
157 (false, []) s 157 end)
158 in 158 (false, []) s
159 EPrim (Prim.String (String.implode (rev chs))) 159 in
160 end 160 EPrim (Prim.String (String.implode (rev chs)))
161 end
162 else
163 e
161 164
162 | EFfiApp ("Basis", "strcat", [(e1, _), (e2, _)]) => exp (EStrcat (e1, e2)) 165 | EFfiApp ("Basis", "strcat", [(e1, _), (e2, _)]) => exp (EStrcat (e1, e2))
163 166
164 | EStrcat ((EPrim (Prim.String s1), loc), (EPrim (Prim.String s2), _)) => 167 | EStrcat ((EPrim (Prim.String s1), loc), (EPrim (Prim.String s2), _)) =>
165 let 168 let