Mercurial > repos > rhope
diff pattern.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 | ed70399a07aa |
children |
line wrap: on
line diff
--- a/pattern.rhope Thu Dec 23 16:16:31 2010 -0500 +++ b/pattern.rhope Fri Jan 07 03:18:33 2011 -0500 @@ -87,11 +87,6 @@ out <- p } -_Match@Empty Pattern[pattern,string,n:num,no match] -{ - no match <- Yes -} - Match@Empty Pattern[pattern,string:num,no match] { no match <- Yes @@ -101,6 +96,33 @@ { num,no match,idx <- [pattern]_Match[string,0,[string]Byte[0]] } +/* +_Match@Pattern[pattern,string,n,b:num,no match,idx] +{ + myb <- [pattern]Byte >> + If[[b]=[myb]] + { + ,check terminal <- [string]Byte[[n]+[1]] + { num,check terminal,idx <- [[pattern]Straight >>]_Match[string, [n]+[1], ~] } + Val[check terminal] + { + ,no match <- If[[pattern]Terminal? >>] + { + num <- [n]+[1] + idx <- Index >>[pattern] + } + } + + }{ + If[[b]<[myb]] + { + num, no match, idx <- [[pattern]Left >>]_Match[string, n,b] + }{ + num, no match, idx <- [[pattern]Right >>]_Match[string, n,b] + } + } +} +*/ _Match@Pattern[pattern,string,n,b:num,no match,idx] { @@ -128,8 +150,51 @@ } } +_Match Iter@Empty Pattern[pattern,origpat,n,count,b,if end:out,next,no next,seekfunc,seek] +{ + out <- Call[if end] { + }{ + If[count] + { + seek <- [count]-[1] + seekfunc <- Val[[origpat]_Match Iter[origpat,[n]+[1],0,?,_No Pattern Match[?]]] + }{ + next <- Val[[origpat]_Match Iter[origpat, [n]+[1], 0, ?, _No Pattern Match[?]]] + no next <- Val[_No Pattern Match[?]] + } + } +} + +_Match Iter@Pattern[pattern,origpat,n,count,b,if end:out,next,no next,seekfunc,seek] +{ + myb <- [pattern]Byte >> + If[[b]=[myb]] + { + ncount <- [count]+[1] + If[[pattern]Terminal? >>] + { next if end <- Val[Val[[[[()]Append[n]]Append[ncount]]Append[[pattern]Index >>],?]] } + { next if end <- Val[_No Pattern Match[?]] } + no next <- Val[next if end] + + next <- Val[[[pattern]Straight >>]_Match Iter[origpat, n, ncount, ?, next if end]] + }{ + If[[b]<[myb]] + { + out,next,no next,seekfunc,seek <- [[pattern]Left >>]_Match Iter[origpat,n,count,b,if end] + }{ + out,next,no next,seekfunc,seek <- [[pattern]Right >>]_Match Iter[origpat,n,count,b,if end] + } + } +} + + _Partition@Pattern[delims,string:matched,after,not found] { + ,not found <- [string]Iter Bytes[_Match Iter[delims,delims,0,0,?,_No Pattern Match[?]], 0] + { + matched, after <- [[string]Substring[[~]Index[0], 0]]Slice[[~]Index[1]] + } + /* not found <- If[[string]=[""]] {} { [delims]Match[string] @@ -139,6 +204,7 @@ matched,after,not found <- _Partition[delims, [string]Substring[1, 0]] } } + */ } _Partition@Empty Pattern[delims,string:matched,after,not found]