* Modules/stropmodule.c: implement find/rfind instead of
index/rindex (raising and catching an exception is much more expensive than returning and testing -1)
This commit is contained in:
parent
3d67feed24
commit
5806a4f5c3
@ -196,7 +196,7 @@ strop_joinfields(self, args)
|
|||||||
|
|
||||||
|
|
||||||
static object *
|
static object *
|
||||||
strop_index(self, args)
|
strop_find(self, args)
|
||||||
object *self; /* Not used */
|
object *self; /* Not used */
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
@ -227,13 +227,12 @@ strop_index(self, args)
|
|||||||
(n == 1 || strncmp(&s[i+1], &sub[1], n-1) == 0))
|
(n == 1 || strncmp(&s[i+1], &sub[1], n-1) == 0))
|
||||||
return newintobject((long)i);
|
return newintobject((long)i);
|
||||||
|
|
||||||
err_setstr(ValueError, "substring not found");
|
return newintobject(-1L);
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static object *
|
static object *
|
||||||
strop_rindex(self, args)
|
strop_rfind(self, args)
|
||||||
object *self; /* Not used */
|
object *self; /* Not used */
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
@ -263,8 +262,7 @@ strop_rindex(self, args)
|
|||||||
(n == 1 || strncmp(&s[j+1], &sub[1], n-1) == 0))
|
(n == 1 || strncmp(&s[j+1], &sub[1], n-1) == 0))
|
||||||
return newintobject((long)j);
|
return newintobject((long)j);
|
||||||
|
|
||||||
err_setstr(ValueError, "substring not found");
|
return newintobject(-1L);
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -512,10 +510,10 @@ static struct methodlist strop_methods[] = {
|
|||||||
{"atof", strop_atof},
|
{"atof", strop_atof},
|
||||||
{"atoi", strop_atoi},
|
{"atoi", strop_atoi},
|
||||||
{"atol", strop_atol},
|
{"atol", strop_atol},
|
||||||
{"index", strop_index},
|
{"find", strop_find},
|
||||||
{"joinfields", strop_joinfields},
|
{"joinfields", strop_joinfields},
|
||||||
{"lower", strop_lower},
|
{"lower", strop_lower},
|
||||||
{"rindex", strop_rindex},
|
{"rfind", strop_rfind},
|
||||||
{"split", strop_split},
|
{"split", strop_split},
|
||||||
{"splitfields", strop_splitfields},
|
{"splitfields", strop_splitfields},
|
||||||
{"strip", strop_strip},
|
{"strip", strop_strip},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user