diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-10-14 09:25:33 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-10-14 09:25:33 (GMT) |
commit | 2bf8993db966256d564d87865ceddf0e33c02500 (patch) | |
tree | 8b172dcec9ee6d9584c75ecc933b418b5210963b /Include | |
parent | ebcf9edc05c03af38c01d8aeb05494b68169756c (diff) | |
download | cpython-2bf8993db966256d564d87865ceddf0e33c02500.zip cpython-2bf8993db966256d564d87865ceddf0e33c02500.tar.gz cpython-2bf8993db966256d564d87865ceddf0e33c02500.tar.bz2 |
Optimize bytes.fromhex() and bytearray.fromhex()
Issue #25401: Optimize bytes.fromhex() and bytearray.fromhex(): they are now
between 2x and 3.5x faster. Changes:
* Use a fast-path working on a char* string for ASCII string
* Use a slow-path for non-ASCII string
* Replace slow hex_digit_to_int() function with a O(1) lookup in
_PyLong_DigitValue precomputed table
* Use _PyBytesWriter API to handle the buffer
* Add unit tests to check the error position in error messages
Diffstat (limited to 'Include')
-rw-r--r-- | Include/bytesobject.h | 3 | ||||
-rw-r--r-- | Include/longobject.h | 2 |
2 files changed, 4 insertions, 1 deletions
diff --git a/Include/bytesobject.h b/Include/bytesobject.h index b5b37ef..4046c1c 100644 --- a/Include/bytesobject.h +++ b/Include/bytesobject.h @@ -67,6 +67,9 @@ PyAPI_FUNC(PyObject*) _PyBytes_FormatEx( Py_ssize_t format_len, PyObject *args, int use_bytearray); +PyAPI_FUNC(PyObject*) _PyBytes_FromHex( + PyObject *string, + int use_bytearray); #endif PyAPI_FUNC(PyObject *) PyBytes_DecodeEscape(const char *, Py_ssize_t, const char *, Py_ssize_t, diff --git a/Include/longobject.h b/Include/longobject.h index ab92495..9574f05 100644 --- a/Include/longobject.h +++ b/Include/longobject.h @@ -65,7 +65,7 @@ PyAPI_FUNC(PyObject *) PyLong_GetInfo(void); # error "void* different in size from int, long and long long" #endif /* SIZEOF_VOID_P */ -/* Used by Python/mystrtoul.c. */ +/* Used by Python/mystrtoul.c and _PyBytes_FromHex(). */ #ifndef Py_LIMITED_API PyAPI_DATA(unsigned char) _PyLong_DigitValue[256]; #endif |