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
e6e43c86
Commit
e6e43c86
authored
May 26, 2006
by
Fredrik Lundh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
needforspeed: stringlib refactoring: use stringlib/find for string find
parent
cc7570fd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
30 deletions
+25
-30
Objects/stringlib/find.h
Objects/stringlib/find.h
+15
-6
Objects/stringobject.c
Objects/stringobject.c
+6
-19
Objects/unicodeobject.c
Objects/unicodeobject.c
+4
-5
No files found.
Objects/stringlib/find.h
View file @
e6e43c86
...
@@ -9,29 +9,38 @@
...
@@ -9,29 +9,38 @@
Py_LOCAL
(
Py_ssize_t
)
Py_LOCAL
(
Py_ssize_t
)
stringlib_find
(
const
STRINGLIB_CHAR
*
str
,
Py_ssize_t
str_len
,
stringlib_find
(
const
STRINGLIB_CHAR
*
str
,
Py_ssize_t
str_len
,
const
STRINGLIB_CHAR
*
sub
,
Py_ssize_t
sub_len
)
const
STRINGLIB_CHAR
*
sub
,
Py_ssize_t
sub_len
,
Py_ssize_t
offset
)
{
{
Py_ssize_t
pos
;
if
(
sub_len
==
0
)
if
(
sub_len
==
0
)
return
0
;
return
offset
;
pos
=
fastsearch
(
str
,
str_len
,
sub
,
sub_len
,
FAST_SEARCH
);
return
fastsearch
(
str
,
str_len
,
sub
,
sub_len
,
FAST_SEARCH
);
if
(
pos
>=
0
)
pos
+=
offset
;
return
pos
;
}
}
Py_LOCAL
(
Py_ssize_t
)
Py_LOCAL
(
Py_ssize_t
)
stringlib_rfind
(
const
STRINGLIB_CHAR
*
str
,
Py_ssize_t
str_len
,
stringlib_rfind
(
const
STRINGLIB_CHAR
*
str
,
Py_ssize_t
str_len
,
const
STRINGLIB_CHAR
*
sub
,
Py_ssize_t
sub_len
)
const
STRINGLIB_CHAR
*
sub
,
Py_ssize_t
sub_len
,
Py_ssize_t
offset
)
{
{
Py_ssize_t
pos
;
Py_ssize_t
pos
;
/* XXX - create reversefastsearch helper! */
/* XXX - create reversefastsearch helper! */
if
(
sub_len
==
0
)
if
(
sub_len
==
0
)
pos
=
str_len
;
pos
=
str_len
+
offset
;
else
{
else
{
Py_ssize_t
j
;
Py_ssize_t
j
;
pos
=
-
1
;
pos
=
-
1
;
for
(
j
=
str_len
-
sub_len
;
j
>=
0
;
--
j
)
for
(
j
=
str_len
-
sub_len
;
j
>=
0
;
--
j
)
if
(
STRINGLIB_CMP
(
str
+
j
,
sub
,
sub_len
)
==
0
)
{
if
(
STRINGLIB_CMP
(
str
+
j
,
sub
,
sub_len
)
==
0
)
{
pos
=
j
;
pos
=
j
+
offset
;
break
;
break
;
}
}
}
}
...
...
Objects/stringobject.c
View file @
e6e43c86
...
@@ -775,6 +775,8 @@ PyString_AsStringAndSize(register PyObject *obj,
...
@@ -775,6 +775,8 @@ PyString_AsStringAndSize(register PyObject *obj,
#define STRINGLIB_EMPTY nullstring
#define STRINGLIB_EMPTY nullstring
#include "stringlib/fastsearch.h"
#include "stringlib/fastsearch.h"
#include "stringlib/find.h"
#include "stringlib/partition.h"
#include "stringlib/partition.h"
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
...
@@ -1876,25 +1878,10 @@ string_find_internal(PyStringObject *self, PyObject *args, int dir)
...
@@ -1876,25 +1878,10 @@ string_find_internal(PyStringObject *self, PyObject *args, int dir)
string_adjust_indices
(
&
i
,
&
last
,
len
);
string_adjust_indices
(
&
i
,
&
last
,
len
);
if
(
n
==
0
)
if
(
dir
>
0
)
return
(
dir
>
0
)
?
i
:
last
;
return
stringlib_find
(
s
+
i
,
last
-
i
,
sub
,
n
,
i
);
if
(
dir
>
0
)
{
else
Py_ssize_t
pos
=
fastsearch
(
s
+
i
,
last
-
i
,
sub
,
n
,
return
stringlib_rfind
(
s
+
i
,
last
-
i
,
sub
,
n
,
i
);
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
;
}
}
...
...
Objects/unicodeobject.c
View file @
e6e43c86
...
@@ -3967,16 +3967,15 @@ Py_ssize_t PyUnicode_Find(PyObject *str,
...
@@ -3967,16 +3967,15 @@ Py_ssize_t PyUnicode_Find(PyObject *str,
if
(
direction
>
0
)
if
(
direction
>
0
)
result
=
stringlib_find
(
result
=
stringlib_find
(
str_obj
->
str
+
start
,
end
-
start
,
sub_obj
->
str
,
sub_obj
->
length
str_obj
->
str
+
start
,
end
-
start
,
sub_obj
->
str
,
sub_obj
->
length
,
start
);
);
else
else
result
=
stringlib_rfind
(
result
=
stringlib_rfind
(
str_obj
->
str
+
start
,
end
-
start
,
sub_obj
->
str
,
sub_obj
->
length
str_obj
->
str
+
start
,
end
-
start
,
sub_obj
->
str
,
sub_obj
->
length
,
start
);
);
if
(
result
>=
0
)
result
+=
start
;
Py_DECREF
(
str_obj
);
Py_DECREF
(
str_obj
);
Py_DECREF
(
sub_obj
);
Py_DECREF
(
sub_obj
);
return
result
;
return
result
;
...
...
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