Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c3434b38
Commit
c3434b38
authored
May 25, 2006
by
Fredrik Lundh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
needforspeed: use fastsearch also for find/index and contains. the
related tests are now about 10x faster.
parent
cfecd599
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
1 deletion
+25
-1
Objects/stringobject.c
Objects/stringobject.c
+25
-1
No files found.
Objects/stringobject.c
View file @
c3434b38
...
...
@@ -1149,10 +1149,14 @@ string_contains(PyObject *a, PyObject *el)
{
char
*
s
=
PyString_AS_STRING
(
a
);
const
char
*
sub
=
PyString_AS_STRING
(
el
);
char
*
last
;
Py_ssize_t
len_sub
=
PyString_GET_SIZE
(
el
);
#ifdef USE_FAST
Py_ssize_t
pos
;
#else
char
*
last
;
Py_ssize_t
shortsub
;
char
firstchar
,
lastchar
;
#endif
if
(
!
PyString_CheckExact
(
el
))
{
#ifdef Py_USING_UNICODE
...
...
@@ -1168,6 +1172,14 @@ string_contains(PyObject *a, PyObject *el)
if
(
len_sub
==
0
)
return
1
;
#ifdef USE_FAST
pos
=
fastsearch
(
s
,
PyString_GET_SIZE
(
a
),
sub
,
len_sub
,
FAST_SEARCH
);
return
(
pos
!=
-
1
);
#else
/* last points to one char beyond the start of the rightmost
substring. When s<last, there is still room for a possible match
and s[0] through s[len_sub-1] will be in bounds.
...
...
@@ -1188,6 +1200,7 @@ string_contains(PyObject *a, PyObject *el)
return
1
;
s
++
;
}
#endif
return
0
;
}
...
...
@@ -1895,6 +1908,17 @@ string_find_internal(PyStringObject *self, PyObject *args, int dir)
string_adjust_indices
(
&
i
,
&
last
,
len
);
#ifdef USE_FAST
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
;
}
#endif
if
(
dir
>
0
)
{
if
(
n
==
0
&&
i
<=
last
)
return
(
long
)
i
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment