Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6b5df906
Commit
6b5df906
authored
Feb 27, 2018
by
Sergey Fedoseev
Committed by
Serhiy Storchaka
Feb 26, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-32147: Improved perfomance of binascii.unhexlify(). (GH-4586)
parent
19e7d48c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
33 deletions
+13
-33
Lib/test/test_binascii.py
Lib/test/test_binascii.py
+5
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS.d/next/Library/2017-11-28-10-23-13.bpo-32147.PI2k1Y.rst
...S.d/next/Library/2017-11-28-10-23-13.bpo-32147.PI2k1Y.rst
+2
-0
Modules/binascii.c
Modules/binascii.c
+5
-33
No files found.
Lib/test/test_binascii.py
View file @
6b5df906
...
...
@@ -198,6 +198,11 @@ class BinASCIITest(unittest.TestCase):
self
.
assertEqual
(
s
,
u
)
self
.
assertRaises
(
binascii
.
Error
,
binascii
.
a2b_hex
,
t
[:
-
1
])
self
.
assertRaises
(
binascii
.
Error
,
binascii
.
a2b_hex
,
t
[:
-
1
]
+
b'q'
)
self
.
assertRaises
(
binascii
.
Error
,
binascii
.
a2b_hex
,
bytes
([
255
,
255
]))
self
.
assertRaises
(
binascii
.
Error
,
binascii
.
a2b_hex
,
b'0G'
)
self
.
assertRaises
(
binascii
.
Error
,
binascii
.
a2b_hex
,
b'0g'
)
self
.
assertRaises
(
binascii
.
Error
,
binascii
.
a2b_hex
,
b'G0'
)
self
.
assertRaises
(
binascii
.
Error
,
binascii
.
a2b_hex
,
b'g0'
)
# Confirm that b2a_hex == hexlify and a2b_hex == unhexlify
self
.
assertEqual
(
binascii
.
hexlify
(
self
.
type2test
(
s
)),
t
)
...
...
Misc/ACKS
View file @
6b5df906
...
...
@@ -460,6 +460,7 @@ Michael Farrell
Troy J. Farrell
Jim Fasarakis-Hilliard
Mark Favas
Sergey Fedoseev
Boris Feld
Thomas Fenzl
Niels Ferguson
...
...
Misc/NEWS.d/next/Library/2017-11-28-10-23-13.bpo-32147.PI2k1Y.rst
0 → 100644
View file @
6b5df906
:func:`binascii.unhexlify` is now up to 2 times faster.
Patch by Sergey Fedoseev.
Modules/binascii.c
View file @
6b5df906
...
...
@@ -1130,21 +1130,6 @@ binascii_hexlify_impl(PyObject *module, Py_buffer *data)
return
_Py_strhex_bytes
((
const
char
*
)
data
->
buf
,
data
->
len
);
}
static
int
to_int
(
int
c
)
{
if
(
Py_ISDIGIT
(
c
))
return
c
-
'0'
;
else
{
if
(
Py_ISUPPER
(
c
))
c
=
Py_TOLOWER
(
c
);
if
(
c
>=
'a'
&&
c
<=
'f'
)
return
c
-
'a'
+
10
;
}
return
-
1
;
}
/*[clinic input]
binascii.a2b_hex
...
...
@@ -1187,9 +1172,9 @@ binascii_a2b_hex_impl(PyObject *module, Py_buffer *hexstr)
retbuf
=
PyBytes_AS_STRING
(
retval
);
for
(
i
=
j
=
0
;
i
<
arglen
;
i
+=
2
)
{
int
top
=
to_int
(
Py_CHARMASK
(
argbuf
[
i
]))
;
int
bot
=
to_int
(
Py_CHARMASK
(
argbuf
[
i
+
1
]))
;
if
(
top
==
-
1
||
bot
==
-
1
)
{
unsigned
int
top
=
_PyLong_DigitValue
[
Py_CHARMASK
(
argbuf
[
i
])]
;
unsigned
int
bot
=
_PyLong_DigitValue
[
Py_CHARMASK
(
argbuf
[
i
+
1
])]
;
if
(
top
>=
16
||
bot
>=
16
)
{
PyErr_SetString
(
Error
,
"Non-hexadecimal digit found"
);
goto
finally
;
...
...
@@ -1218,19 +1203,6 @@ binascii_unhexlify_impl(PyObject *module, Py_buffer *hexstr)
return
binascii_a2b_hex_impl
(
module
,
hexstr
);
}
static
const
int
table_hex
[
128
]
=
{
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
10
,
11
,
12
,
13
,
14
,
15
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
10
,
11
,
12
,
13
,
14
,
15
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
};
#define hexval(c) table_hex[(unsigned int)(c)]
#define MAXLINESIZE 76
...
...
@@ -1293,9 +1265,9 @@ binascii_a2b_qp_impl(PyObject *module, Py_buffer *data, int header)
(
ascii_data
[
in
+
1
]
>=
'a'
&&
ascii_data
[
in
+
1
]
<=
'f'
)
||
(
ascii_data
[
in
+
1
]
>=
'0'
&&
ascii_data
[
in
+
1
]
<=
'9'
)))
{
/* hexval */
ch
=
hexval
(
ascii_data
[
in
])
<<
4
;
ch
=
_PyLong_DigitValue
[
ascii_data
[
in
]]
<<
4
;
in
++
;
ch
|=
hexval
(
ascii_data
[
in
])
;
ch
|=
_PyLong_DigitValue
[
ascii_data
[
in
]]
;
in
++
;
odata
[
out
++
]
=
ch
;
}
...
...
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