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
3d6f0126
Commit
3d6f0126
authored
Mar 07, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make sure we always optimise bytearray.append(INT_LITERAL)
parent
73e24e80
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
11 deletions
+13
-11
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+1
-1
tests/run/bytearraymethods.pyx
tests/run/bytearraymethods.pyx
+12
-10
No files found.
Cython/Compiler/Optimize.py
View file @
3d6f0126
...
...
@@ -2450,7 +2450,7 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
func_type
=
self
.
PyByteArray_Append_func_type
value
=
unwrap_coerced_node
(
args
[
1
])
if
value
.
type
.
is_int
:
if
value
.
type
.
is_int
or
isinstance
(
value
,
ExprNodes
.
IntNode
)
:
value
=
value
.
coerce_to
(
PyrexTypes
.
c_int_type
,
self
.
current_env
())
utility_code
=
UtilityCode
.
load_cached
(
"ByteArrayAppend"
,
"StringTools.c"
)
elif
value
.
is_string_literal
:
...
...
tests/run/bytearraymethods.pyx
View file @
3d6f0126
...
...
@@ -198,23 +198,24 @@ def bytearray_decode_unbound_method(bytearray s, start=None, stop=None):
else
:
return
bytearray
.
decode
(
s
[
start
:
stop
],
'utf8'
)
@
cython
.
test_fail_if_path_exists
(
'//SimpleCallNode'
)
@
cython
.
test_assert_path_exists
(
'//PythonCapiCallNode'
)
def
bytearray_append
(
bytearray
b
,
signed
char
c
,
int
i
,
object
o
):
"""
>>> b = bytearray(b'abc')
>>> b = bytearray_append(b, ord('x'), ord('y'), ord('z'))
>>> print(b.decode('ascii'))
abcXxyz
abcX
@
xyz
>>> b = bytearray(b'abc')
>>> b = bytearray_append(b, ord('x'), ord('y'), ord('z') if IS_PY3 else b'z')
>>> print(b.decode('ascii'))
abcXxyz
abcX
@
xyz
>>> b = bytearray(b'abc')
>>> b = bytearray_append(b, ord('x'), ord('y'), ord('
\
\
xc3') if IS_PY3 else b'
\
\
xc3')
>>> print(b[:-1].decode('ascii'))
abcXxy
abcX
@
xy
>>> print('%x' % b[-1])
c3
...
...
@@ -224,44 +225,45 @@ def bytearray_append(bytearray b, signed char c, int i, object o):
... except (TypeError, ValueError): pass # (Py3, Py2)
... else: print("FAIL")
>>> print(b.decode('ascii'))
abcXxy
abcX
@
xy
>>> b = bytearray(b'abc')
>>> b = bytearray_append(b, -1, ord('y'), ord('z')) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
>>> print(b.decode('ascii'))
abcX
abcX
@
>>> b = bytearray(b'abc')
>>> b = bytearray_append(b, ord('x'), -1, ord('z')) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
>>> print(b.decode('ascii'))
abcXx
abcX
@
x
>>> b = bytearray(b'abc')
>>> b = bytearray_append(b, ord('x'), 256, ord('z')) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
>>> print(b.decode('ascii'))
abcXx
abcX
@
x
>>> b = bytearray(b'abc')
>>> b = bytearray_append(b, ord('x'), ord('y'), -1) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
>>> print(b.decode('ascii'))
abcXxy
abcX
@
xy
>>> b = bytearray(b'abc')
>>> b = bytearray_append(b, ord('x'), ord('y'), 256) # doctest: +ELLIPSIS
Traceback (most recent call last):
ValueError: ...
>>> print(b.decode('ascii'))
abcXxy
abcX
@
xy
"""
assert
b
.
append
(
'X'
)
is
None
b
.
append
(
64
)
b
.
append
(
c
)
b
.
append
(
i
)
b
.
append
(
o
)
...
...
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