diff Modules/stropmodule.c @ 1787:cb84dd51c2aa legacy-trunk

* Modules/stropmodule.c: implement find/rfind instead of index/rindex (raising and catching an exception is much more expensive than returning and testing -1)
author Guido van Rossum <guido@python.org>
date Wed, 17 Aug 1994 13:15:46 +0000
parents 48e6b319f3e4
children be956b1efb97
line wrap: on
line diff
--- a/Modules/stropmodule.c	Wed Aug 17 12:33:50 1994 +0000
+++ b/Modules/stropmodule.c	Wed Aug 17 13:15:46 1994 +0000
@@ -196,7 +196,7 @@
 
 
 static object *
-strop_index(self, args)
+strop_find(self, args)
 	object *self; /* Not used */
 	object *args;
 {
@@ -227,13 +227,12 @@
 		    (n == 1 || strncmp(&s[i+1], &sub[1], n-1) == 0))
 			return newintobject((long)i);
 
-	err_setstr(ValueError, "substring not found");
-	return NULL;
+	return newintobject(-1L);
 }
 
 
 static object *
-strop_rindex(self, args)
+strop_rfind(self, args)
 	object *self; /* Not used */
 	object *args;
 {
@@ -263,8 +262,7 @@
 		    (n == 1 || strncmp(&s[j+1], &sub[1], n-1) == 0))
 			return newintobject((long)j);
 
-	err_setstr(ValueError, "substring not found");
-	return NULL;
+	return newintobject(-1L);
 }
 
 
@@ -512,10 +510,10 @@
 	{"atof",	strop_atof},
 	{"atoi",	strop_atoi},
 	{"atol",	strop_atol},
-	{"index",	strop_index},
+	{"find",	strop_find},
 	{"joinfields",	strop_joinfields},
 	{"lower",	strop_lower},
-	{"rindex",	strop_rindex},
+	{"rfind",	strop_rfind},
 	{"split",	strop_split},
 	{"splitfields",	strop_splitfields},
 	{"strip",	strop_strip},