Skip to content

Commit

Permalink
Let python 3.3+ handle fast path pure ascii text
Browse files Browse the repository at this point in the history
That is most text when using SQLite.  perf showed a small consistent
improvement in speedtest

Refs #288
  • Loading branch information
rogerbinns committed Jun 16, 2020
1 parent 834349a commit 26a5b3a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions doc/changes.rst
Expand Up @@ -2,6 +2,11 @@ Change History
**************
.. currentmodule:: apsw

next-r1
=======

Small performance improvement in string handling

3.32.2-r1
=========

Expand Down
6 changes: 4 additions & 2 deletions src/pyutil.c
Expand Up @@ -247,8 +247,10 @@ convertutf8stringsize(const char *str, Py_ssize_t size)
assert(str);
assert(size >= 0);

#if PY_VERSION_HEX < 0x03030000
/* Performance optimization: If str is all ascii then we
can just make a unicode object and fill in the chars. PyUnicode_DecodeUTF8 is rather long
can just make a unicode object and fill in the chars. PyUnicode_DecodeUTF8 is rather long,
but was fixed in later Python 3 releases
*/
if (size < 16384)
{
Expand Down Expand Up @@ -280,7 +282,7 @@ convertutf8stringsize(const char *str, Py_ssize_t size)
APSW_Unicode_Return(res);
}
}

#endif
{
PyObject *r = PyUnicode_DecodeUTF8(str, size, NULL);
APSW_Unicode_Return(r);
Expand Down

0 comments on commit 26a5b3a

Please sign in to comment.