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
046d77d9
Commit
046d77d9
authored
Dec 07, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
also optimise basestring.join() since we now infer this type in a couple of places
parent
00980f04
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
1 deletion
+28
-1
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+4
-1
Cython/Utility/StringTools.c
Cython/Utility/StringTools.c
+2
-0
tests/run/builtin_basestring.pyx
tests/run/builtin_basestring.pyx
+22
-0
No files found.
Cython/Compiler/Builtin.py
View file @
046d77d9
...
...
@@ -276,7 +276,10 @@ builtin_types_table = [
BuiltinAttribute
(
'imag'
,
'cval.imag'
,
field_type
=
PyrexTypes
.
c_double_type
),
]),
(
"basestring"
,
"PyBaseString_Type"
,
[]),
(
"basestring"
,
"PyBaseString_Type"
,
[
BuiltinMethod
(
"join"
,
"TO"
,
"T"
,
"__Pyx_PyBaseString_Join"
,
utility_code
=
UtilityCode
.
load
(
"StringJoin"
,
"StringTools.c"
)),
]),
(
"bytearray"
,
"PyByteArray_Type"
,
[]),
(
"bytes"
,
"PyBytes_Type"
,
[
BuiltinMethod
(
"__contains__"
,
"TO"
,
"b"
,
"PySequence_Contains"
),
BuiltinMethod
(
"join"
,
"TO"
,
"O"
,
"__Pyx_PyBytes_Join"
,
...
...
Cython/Utility/StringTools.c
View file @
046d77d9
...
...
@@ -654,8 +654,10 @@ static CYTHON_INLINE char __Pyx_PyBytes_GetItemInt(PyObject* bytes, Py_ssize_t i
#if PY_MAJOR_VERSION < 3
#define __Pyx_PyString_Join __Pyx_PyBytes_Join
#define __Pyx_PyBaseString_Join(s, v) (PyUnicode_CheckExact(s) ? PyUnicode_Join(s, v) : __Pyx_PyBytes_Join(s, v))
#else
#define __Pyx_PyString_Join PyUnicode_Join
#define __Pyx_PyBaseString_Join PyUnicode_Join
#endif
#if CYTHON_COMPILING_IN_CPYTHON
...
...
tests/run/builtin_basestring.pyx
View file @
046d77d9
cimport
cython
import
sys
IS_PY3
=
sys
.
version_info
[
0
]
>=
3
...
...
@@ -84,3 +86,23 @@ def basestring_typed_argument(basestring obj):
TypeError: ...got S...
"""
return
obj
@
cython
.
test_assert_path_exists
(
"//SimpleCallNode"
,
"//SimpleCallNode//NoneCheckNode"
,
"//SimpleCallNode//AttributeNode[@is_py_attr = false]"
)
def
basestring_join
(
basestring
s
,
*
values
):
"""
>>> print(basestring_join(ustring, 'a', 'b', 'c'))
aabcdefbabcdefc
>>> print(basestring_join(sstring, 'a', 'b', 'c'))
aabcdefbabcdefc
>>> if IS_PY3: print('abcdefabcdefabcdef')
... else: print(basestring_join(bstring, bstring, bstring).decode('utf8'))
abcdefabcdefabcdef
>>> basestring_join(None, 'a', 'b', 'c')
Traceback (most recent call last):
AttributeError: 'NoneType' object has no attribute 'join'
"""
return
s
.
join
(
values
)
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