Add asciilib: similar to ucs1, ucs2 and ucs4 library, but specialized… · pythoncapi/cpython@c3cec78 · GitHub
Skip to content

Commit c3cec78

Browse files
author
Victor Stinner
committed
Add asciilib: similar to ucs1, ucs2 and ucs4 library, but specialized to ASCII
ucs1, ucs2 and ucs4 libraries have to scan created substring to find the maximum character, whereas it is not need to ASCII strings. Because ASCII strings are common, it is useful to optimize ASCII.
1 parent 14f8f02 commit c3cec78

4 files changed

Lines changed: 153 additions & 49 deletions

File tree

Include/unicodeobject.h

Lines changed: 1 addition & 0 deletions

Objects/stringlib/asciilib.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* this is sort of a hack. there's at least one place (formatting
2+
floats) where some stringlib code takes a different path if it's
3+
compiled as unicode. */
4+
#define STRINGLIB_IS_UNICODE 1
5+
6+
#define FASTSEARCH asciilib_fastsearch
7+
#define STRINGLIB(F) asciilib_##F
8+
#define STRINGLIB_OBJECT PyUnicodeObject
9+
#define STRINGLIB_CHAR Py_UCS1
10+
#define STRINGLIB_TYPE_NAME "unicode"
11+
#define STRINGLIB_PARSE_CODE "U"
12+
#define STRINGLIB_EMPTY unicode_empty
13+
#define STRINGLIB_ISSPACE Py_UNICODE_ISSPACE
14+
#define STRINGLIB_ISLINEBREAK BLOOM_LINEBREAK
15+
#define STRINGLIB_ISDECIMAL Py_UNICODE_ISDECIMAL
16+
#define STRINGLIB_TODECIMAL Py_UNICODE_TODECIMAL
17+
#define STRINGLIB_TOUPPER Py_UNICODE_TOUPPER
18+
#define STRINGLIB_TOLOWER Py_UNICODE_TOLOWER
19+
#define STRINGLIB_FILL Py_UNICODE_FILL
20+
#define STRINGLIB_STR PyUnicode_1BYTE_DATA
21+
#define STRINGLIB_LEN PyUnicode_GET_LENGTH
22+
#define STRINGLIB_NEW unicode_fromascii
23+
#define STRINGLIB_RESIZE not_supported
24+
#define STRINGLIB_CHECK PyUnicode_Check
25+
#define STRINGLIB_CHECK_EXACT PyUnicode_CheckExact
26+
#define STRINGLIB_GROUPING _PyUnicode_InsertThousandsGrouping
27+
#define STRINGLIB_GROUPING_LOCALE _PyUnicode_InsertThousandsGroupingLocale
28+
29+
#define STRINGLIB_TOSTR PyObject_Str
30+
#define STRINGLIB_TOASCII PyObject_ASCII
31+
32+
#define _Py_InsertThousandsGrouping _PyUnicode_ascii_InsertThousandsGrouping
33+
#define _Py_InsertThousandsGroupingLocale _PyUnicode_ascii_InsertThousandsGroupingLocale
34+

Objects/unicodeobject.c

Lines changed: 116 additions & 47 deletions

0 commit comments

Comments
 (0)