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
fc634304
Commit
fc634304
authored
Aug 29, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
speed up appending integer values to bytearray objects in Py3
parent
f6439a49
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
+21
-0
Cython/Utility/StringTools.c
Cython/Utility/StringTools.c
+14
-0
tests/run/bytearraymethods.pyx
tests/run/bytearraymethods.pyx
+7
-0
No files found.
Cython/Utility/StringTools.c
View file @
fc634304
...
...
@@ -728,6 +728,20 @@ static CYTHON_INLINE int __Pyx_PyByteArray_AppendObject(PyObject* bytearray, PyO
}
ival
=
(
unsigned
char
)
(
PyString_AS_STRING
(
value
)[
0
]);
}
else
#else
#if CYTHON_USE_PYLONG_INTERNALS
if
(
likely
(
PyLong_CheckExact
(
value
))
&&
likely
(
Py_SIZE
(
value
)
==
1
||
Py_SIZE
(
value
)
==
0
))
{
if
(
Py_SIZE
(
value
)
==
0
)
{
ival
=
0
;
}
else
{
ival
=
((
PyLongObject
*
)
value
)
->
ob_digit
[
0
];
if
(
unlikely
(
ival
>
255
))
{
PyErr_SetString
(
PyExc_ValueError
,
"byte must be in range(0, 256)"
);
return
-
1
;
}
}
}
else
#endif
#endif
{
// CPython calls PyNumber_Index() internally
...
...
tests/run/bytearraymethods.pyx
View file @
fc634304
...
...
@@ -207,6 +207,13 @@ def bytearray_append(bytearray b, signed char c, int i, object o):
>>> print(b.decode('ascii'))
abcX@xyz
>>> b = bytearray(b'abc')
>>> b = bytearray_append(b, ord('x'), ord('y'), 0)
>>> print(b.decode('ascii')[:-1])
abcX@xy
>>> b[-1]
0
>>> b = bytearray(b'abc')
>>> b = bytearray_append(b, ord('x'), ord('y'), ord('z') if IS_PY3 else b'z')
>>> print(b.decode('ascii'))
...
...
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