changeset 153:d86df83402f3

Small performance optimization in string lib
author Mike Pavone <pavone@retrodev.com>
date Tue, 21 Dec 2010 04:11:29 +0000
parents e9a8269384bb
children 29b479a2ce48
files pattern.rhope string.rhope
diffstat 2 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/pattern.rhope	Sun Dec 05 18:04:54 2010 -0500
+++ b/pattern.rhope	Tue Dec 21 04:11:29 2010 +0000
@@ -100,16 +100,17 @@
 
 Match@Pattern[pattern,string:num,no match,idx]
 {
-	num,no match,idx <- [pattern]_Match[string,0]
+	num,no match,idx <- [pattern]_Match[string,0,[string]Byte[0]]
 }
 
-_Match@Pattern[pattern,string,n:num,no match,idx]
+_Match@Pattern[pattern,string,n,b:num,no match,idx]
 {
-	b <- [string]Byte[n]
 	myb <- [pattern]Byte >>
 	If[[b]=[myb]]
 	{
-		num, ,idx <- [[pattern]Straight >>]_Match[string, [n]+[1]] { }
+		,check terminal <- [string]Byte[[n]+[1]]
+		{ num,check terminal,idx <- [[pattern]Straight >>]_Match[string, [n]+[1], ~] }
+		Val[check terminal]
 		{
 			,no match <- If[[pattern]Terminal? >>]
 			{
@@ -121,10 +122,11 @@
 	}{
 		If[[b]<[myb]]
 		{
-			num, no match, idx <- [[pattern]Left >>]_Match[string, n]
+			num, no match, idx <- [[pattern]Left >>]_Match[string, n,b]
 		}{
-			num, no match, idx <- [[pattern]Right >>]_Match[string, n]
+			num, no match, idx <- [[pattern]Right >>]_Match[string, n,b]
 		}
 	}
 }
 
+
--- a/string.rhope	Sun Dec 05 18:04:54 2010 -0500
+++ b/string.rhope	Tue Dec 21 04:11:29 2010 +0000
@@ -446,7 +446,9 @@
 			left <- ""
 			right <- string
 		}{
-			sliceoffset <- CPOff to BOff[[string]Buffer >>, 0i32, 0i32, slicepoint]
+			If[[[string]Length] = [[string]Byte Length]]
+			{ sliceoffset <- Val[slicepoint] }
+			{ sliceoffset <- CPOff to BOff[[string]Buffer >>, 0i32, 0i32, slicepoint] }
 			left <- String Slice[string, 0i32, slicepoint, sliceoffset]
 			right <- String Slice[string, sliceoffset, [[string]Length >>]-[slicepoint], [[[string]Buffer >>]Length]-[sliceoffset]]
 		}
@@ -650,7 +652,9 @@
 			left <- ""
 			right <- string
 		}{
-			sliceoffset <- CPOff to BOff[[[string]Source >>]Buffer >>, 0i32, [string]Offset >>, slicepoint]
+			If[[[string]Length]=[[string]Byte Length]]
+			{ sliceoffset <- [[string]Offset >>]+[slicepoint] }
+			{ sliceoffset <- CPOff to BOff[[[string]Source >>]Buffer >>, 0i32, [string]Offset >>, slicepoint] }
 			left <- String Slice[[string]Source >>, [string]Offset >>, slicepoint, [sliceoffset]-[[string]Offset >>]]
 			right <- String Slice[[string]Source >>, sliceoffset, [[string]Length >>]-[slicepoint], [[string]Byte Length]-[[sliceoffset]-[[string]Offset >>]]]
 		}