[New-bugs-announce] [issue37348] add _PyUnicode_FROM_ASCII macro
Inada Naoki
report at bugs.python.org
Thu Jun 20 07:40:57 EDT 2019
New submission from Inada Naoki <songofacandy at gmail.com>:
_PyUnicode_FromASCII(s, len) is faster than PyUnicode_FromString(s) because PyUnicode_FromString() uses temporary _PyUnicodeWriter to support UTF-8.
But _PyUnicode_FromASCII("hello", strlen("hello"))` is not as easy as `PyUnicode_FromString("hello")`.
_PyUnicode_FROM_ASCII() is simple macro which wraps _PyUnicode_FromASCII which calls strlen() automatically:
```
/* Convenient wrapper for _PyUnicode_FromASCII */
#define _PyUnicode_FROM_ASCII(s) _PyUnicode_FromASCII((s), strlen(s))
```
I believe recent compilers optimize away calls of strlen().
----------
components: Interpreter Core
messages: 346115
nosy: inada.naoki
priority: normal
severity: normal
status: open
title: add _PyUnicode_FROM_ASCII macro
type: performance
versions: Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37348>
_______________________________________
More information about the New-bugs-announce
mailing list