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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
4efe2844
Commit
4efe2844
authored
Feb 22, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimise 'x in unicode' a bit
parent
baac46e8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
0 deletions
+32
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+5
-0
Cython/Utility/StringTools.c
Cython/Utility/StringTools.c
+8
-0
tests/run/unicodemethods.pyx
tests/run/unicodemethods.pyx
+19
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
4efe2844
...
...
@@ -9155,6 +9155,11 @@ class CmpNode(object):
self
.
special_bool_cmp_utility_code
=
UtilityCode
.
load_cached
(
"PyDictContains"
,
"ObjectHandling.c"
)
self
.
special_bool_cmp_function
=
"__Pyx_PyDict_Contains"
return
True
elif
self
.
operand2
.
type
is
Builtin
.
unicode_type
:
self
.
operand2
=
self
.
operand2
.
as_none_safe_node
(
"'NoneType' object is not iterable"
)
self
.
special_bool_cmp_utility_code
=
UtilityCode
.
load_cached
(
"PyUnicodeContains"
,
"StringTools.c"
)
self
.
special_bool_cmp_function
=
"__Pyx_PyUnicode_Contains"
return
True
else
:
if
not
self
.
operand2
.
type
.
is_pyobject
:
self
.
operand2
=
self
.
operand2
.
coerce_to_pyobject
(
env
)
...
...
Cython/Utility/StringTools.c
View file @
4efe2844
...
...
@@ -109,6 +109,14 @@ static CYTHON_INLINE int __Pyx_PyUnicodeBufferContainsUCS4(Py_UNICODE* buffer, P
}
//////////////////// PyUnicodeContains.proto ////////////////////
static
CYTHON_INLINE
int
__Pyx_PyUnicode_Contains
(
PyObject
*
substring
,
PyObject
*
text
,
int
eq
)
{
int
result
=
PyUnicode_Contains
(
text
,
substring
);
return
unlikely
(
result
<
0
)
?
result
:
(
result
==
(
eq
==
Py_EQ
));
}
//////////////////// StrEquals.proto ////////////////////
//@requires: BytesEquals
//@requires: UnicodeEquals
...
...
tests/run/unicodemethods.pyx
View file @
4efe2844
...
...
@@ -364,6 +364,25 @@ def endswith_start_end(unicode s, sub, start, end):
return
'NO MATCH'
# unicode.__contains__(s, sub)
@
cython
.
test_fail_if_path_exists
(
"//CoerceFromPyTypeNode"
,
"//AttributeNode"
)
@
cython
.
test_assert_path_exists
(
"//CoerceToPyTypeNode"
,
"//PrimaryCmpNode"
)
def
in_test
(
unicode
s
,
substring
):
"""
>>> in_test(text, 'sa')
True
>>> in_test(text, 'XYZ')
False
>>> in_test(None, 'sa')
Traceback (most recent call last):
TypeError: 'NoneType' object is not iterable
"""
return
substring
in
s
# unicode.find(s, sub, [start, [end]])
@
cython
.
test_fail_if_path_exists
(
...
...
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