diff Objects/stringobject.c @ 38404:52f2c9f74f5a legacy-trunk

needforspeed: stringlib refactoring: use stringlib/find for string find
author Fredrik Lundh <fredrik@pythonware.com>
date Fri, 26 May 2006 19:48:07 +0000
parents 33c328896f52
children 4697d1958ccb
line wrap: on
line diff
--- a/Objects/stringobject.c	Fri May 26 19:43:45 2006 +0000
+++ b/Objects/stringobject.c	Fri May 26 19:48:07 2006 +0000
@@ -775,6 +775,8 @@
 #define STRINGLIB_EMPTY nullstring
 
 #include "stringlib/fastsearch.h"
+
+#include "stringlib/find.h"
 #include "stringlib/partition.h"
 
 /* -------------------------------------------------------------------- */
@@ -1876,25 +1878,10 @@
 
 	string_adjust_indices(&i, &last, len);
 
-	if (n == 0)
-		return (dir > 0) ? i : last;
-	if (dir > 0) {
-		Py_ssize_t pos = fastsearch(s + i, last - i, sub, n,
-					    FAST_SEARCH);
-		if (pos < 0)
-			return pos;
-		return pos + i;
-	} else {
-		Py_ssize_t j;
-
-        	if (n == 0 && i <= last)
-			return last;
-		for (j = last-n; j >= i; --j)
-			if (s[j] == sub[0] && memcmp(&s[j], sub, n) == 0)
-				return j;
-	}
-
-	return -1;
+	if (dir > 0)
+		return stringlib_find(s+i, last-i, sub, n, i);
+	else
+		return stringlib_rfind(s+i, last-i, sub, n, i);
 }