Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
760d0429
Commit
760d0429
authored
Jan 02, 2017
by
scoder
Committed by
GitHub
Jan 02, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1571 from klaussfreire/optimize_string_comparisons
Optimize string comparisons
parents
9be812eb
74b31485
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
0 deletions
+26
-0
Cython/Utility/StringTools.c
Cython/Utility/StringTools.c
+26
-0
No files found.
Cython/Utility/StringTools.c
View file @
760d0429
...
@@ -14,6 +14,7 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
...
@@ -14,6 +14,7 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/
//////////////////// InitStrings ////////////////////
//////////////////// InitStrings ////////////////////
static
int
__Pyx_InitStrings
(
__Pyx_StringTabEntry
*
t
)
{
static
int
__Pyx_InitStrings
(
__Pyx_StringTabEntry
*
t
)
{
long
hash
;
while
(
t
->
p
)
{
while
(
t
->
p
)
{
#if PY_MAJOR_VERSION < 3
#if PY_MAJOR_VERSION < 3
if
(
t
->
is_unicode
)
{
if
(
t
->
is_unicode
)
{
...
@@ -38,6 +39,9 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
...
@@ -38,6 +39,9 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
#endif
#endif
if
(
!*
t
->
p
)
if
(
!*
t
->
p
)
return
-
1
;
return
-
1
;
hash
=
PyObject_Hash
(
*
t
->
p
);
if
(
hash
==
-
1
)
PyErr_Clear
();
++
t
;
++
t
;
}
}
return
0
;
return
0
;
...
@@ -185,6 +189,21 @@ static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int
...
@@ -185,6 +189,21 @@ static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int
if
(
length
!=
__Pyx_PyUnicode_GET_LENGTH
(
s2
))
{
if
(
length
!=
__Pyx_PyUnicode_GET_LENGTH
(
s2
))
{
goto
return_ne
;
goto
return_ne
;
}
}
#if CYTHON_COMPILING_IN_CPYTHON
#if CYTHON_PEP393_ENABLED
if
(((
PyASCIIObject
*
)
s1
)
->
hash
!=
((
PyASCIIObject
*
)
s2
)
->
hash
&&
((
PyASCIIObject
*
)
s1
)
->
hash
!=
-
1
&&
((
PyASCIIObject
*
)
s2
)
->
hash
!=
-
1
)
{
goto
return_ne
;
}
#else
if
(((
PyUnicodeObject
*
)
s1
)
->
hash
!=
((
PyUnicodeObject
*
)
s2
)
->
hash
&&
((
PyUnicodeObject
*
)
s1
)
->
hash
!=
-
1
&&
((
PyUnicodeObject
*
)
s2
)
->
hash
!=
-
1
)
{
goto
return_ne
;
}
#endif
#endif
// len(s1) == len(s2) >= 1 (empty string is interned, and "s1 is not s2")
// len(s1) == len(s2) >= 1 (empty string is interned, and "s1 is not s2")
kind
=
__Pyx_PyUnicode_KIND
(
s1
);
kind
=
__Pyx_PyUnicode_KIND
(
s1
);
if
(
kind
!=
__Pyx_PyUnicode_KIND
(
s2
))
{
if
(
kind
!=
__Pyx_PyUnicode_KIND
(
s2
))
{
...
@@ -257,6 +276,13 @@ static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int eq
...
@@ -257,6 +276,13 @@ static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int eq
}
else
if
(
length
==
1
)
{
}
else
if
(
length
==
1
)
{
return
(
equals
==
Py_EQ
);
return
(
equals
==
Py_EQ
);
}
else
{
}
else
{
#if CYTHON_COMPILING_IN_CPYTHON
if
(((
PyBytesObject
*
)
s1
)
->
ob_shash
!=
((
PyBytesObject
*
)
s2
)
->
ob_shash
&&
((
PyBytesObject
*
)
s1
)
->
ob_shash
!=
-
1
&&
((
PyBytesObject
*
)
s2
)
->
ob_shash
!=
-
1
)
{
return
(
equals
==
Py_NE
);
}
#endif
int
result
=
memcmp
(
ps1
,
ps2
,
(
size_t
)
length
);
int
result
=
memcmp
(
ps1
,
ps2
,
(
size_t
)
length
);
return
(
equals
==
Py_EQ
)
?
(
result
==
0
)
:
(
result
!=
0
);
return
(
equals
==
Py_EQ
)
?
(
result
==
0
)
:
(
result
!=
0
);
}
}
...
...
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