comparison string.rhope @ 160:f97a7d499182

Optimize _Partition@Pattern using a byte iterator
author Mike Pavone <pavone@retrodev.com>
date Fri, 07 Jan 2011 03:18:33 -0500
parents 0e06f29aa83d
children 64be565a40c6
comparison
equal deleted inserted replaced
158:0e06f29aa83d 160:f97a7d499182
1140 String@String Slice[string:out] 1140 String@String Slice[string:out]
1141 { 1141 {
1142 out <- string 1142 out <- string
1143 } 1143 }
1144 1144
1145 _No Pattern Match[:out,no match]
1146 {
1147 no match <- Yes
1148 }
1149
1150 _Iter Bytes Buf[buf,offset,first,last,func,if end:out,end,seekfout,seekout]
1151 {
1152 [buf]Index[offset]
1153 {
1154 out,nextf,no next,seekf,seek <- [func]Call[~] {}
1155 {
1156 If[[offset]<[last]]
1157 { out,end <- _Iter Bytes Buf[buf, [offset]+[1], first, last, nextf, no next] }
1158 { end <- [[()]Append[nextf]]Append[no next] }
1159 }{}{
1160 newoff <- [offset]-[seek]
1161 If[[newoff]<[first]]
1162 {
1163 seekfout <- Val[seekf]
1164 seekout <- [first]-[newoff]
1165 }{ out,end <- _Iter Bytes Buf[buf, newoff, first, last, seekf, _No Pattern Match[?]] }
1166 }
1167 }{
1168 end <- [[()]Append[func]]Append[if end]
1169 }
1170 }
1171
1172 _Iter Bytes@String[string,func,start,if end:out,end,seekfunc,seek]
1173 {
1174 out,end,seekfunc,seek <- _Iter Bytes Buf[[string]Buffer >>, start, 0, [[string]Byte Length]-[1], func, if end]
1175 }
1176
1177 _Iter Bytes@String Slice[string,func,start,if end:out,end,seekfunc,seek]
1178 {
1179 out,end,seekfunc,seek <- _Iter Bytes Buf[[[string]Source >>]Buffer >>, [[string]Offset >>]+[start], [string]Offset >>, [[[string]Byte Length]-[1]]+[[string]Offset >>], func, if end]
1180 }
1181
1182 _Iter Bytes@String Cat[string,func,start,if end:out,end,seekfunc,seek]
1183 {
1184 llen <- [[string]Left >>]Byte Length
1185 If[[start]<[llen]]
1186 {
1187 out,,seekfunc,seek <- [[string]Left >>]_Iter Bytes[func, start, if end] {}
1188 {
1189 right off <- 0
1190 right func <- [~]Index[0]
1191 right if end <- [~]Index[1]
1192 }
1193 }{
1194 right off <- [start]-[llen]
1195 right func <- Val[func]
1196 right if end <- Val[if end]
1197 }
1198
1199 Val[right off]
1200 {
1201 out,end,,rseek <- [[string]Right >>]_Iter Bytes[right func, ~, right if end] {} {}
1202 {
1203 out,end,seekfunc,seek <- [string]_Iter Bytes[~, [llen]-[rseek], _No Pattern Match[?]]
1204 }
1205 }
1206 }
1207
1208 Iter Bytes[string,func,start:out,end]
1209 {
1210 out <- [string]_Iter Bytes[func, start, _No Pattern Match[?]] {}
1211 {
1212 out <- Call[[~]Index[1]] {}
1213 {
1214 end <- Yes
1215 }
1216 }
1217 { end <- Yes }
1218 }
1219
1145 Replace[string,otoreplace,with:out] 1220 Replace[string,otoreplace,with:out]
1146 { 1221 {
1147 toreplace <- Pattern[otoreplace] 1222 toreplace <- Pattern[otoreplace]
1148 ,delim,after <-[string]Partition[toreplace] 1223 ,delim,after <-[string]Partition[toreplace]
1149 { 1224 {