Commit 046d77d9 authored by Stefan Behnel's avatar Stefan Behnel

also optimise basestring.join() since we now infer this type in a couple of places

parent 00980f04
...@@ -276,7 +276,10 @@ builtin_types_table = [ ...@@ -276,7 +276,10 @@ builtin_types_table = [
BuiltinAttribute('imag', 'cval.imag', field_type = PyrexTypes.c_double_type), 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", []), ("bytearray", "PyByteArray_Type", []),
("bytes", "PyBytes_Type", [BuiltinMethod("__contains__", "TO", "b", "PySequence_Contains"), ("bytes", "PyBytes_Type", [BuiltinMethod("__contains__", "TO", "b", "PySequence_Contains"),
BuiltinMethod("join", "TO", "O", "__Pyx_PyBytes_Join", BuiltinMethod("join", "TO", "O", "__Pyx_PyBytes_Join",
......
...@@ -654,8 +654,10 @@ static CYTHON_INLINE char __Pyx_PyBytes_GetItemInt(PyObject* bytes, Py_ssize_t i ...@@ -654,8 +654,10 @@ static CYTHON_INLINE char __Pyx_PyBytes_GetItemInt(PyObject* bytes, Py_ssize_t i
#if PY_MAJOR_VERSION < 3 #if PY_MAJOR_VERSION < 3
#define __Pyx_PyString_Join __Pyx_PyBytes_Join #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 #else
#define __Pyx_PyString_Join PyUnicode_Join #define __Pyx_PyString_Join PyUnicode_Join
#define __Pyx_PyBaseString_Join PyUnicode_Join
#endif #endif
#if CYTHON_COMPILING_IN_CPYTHON #if CYTHON_COMPILING_IN_CPYTHON
......
cimport cython
import sys import sys
IS_PY3 = sys.version_info[0] >= 3 IS_PY3 = sys.version_info[0] >= 3
...@@ -84,3 +86,23 @@ def basestring_typed_argument(basestring obj): ...@@ -84,3 +86,23 @@ def basestring_typed_argument(basestring obj):
TypeError: ...got S... TypeError: ...got S...
""" """
return obj 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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment