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
dfb39758
Commit
dfb39758
authored
Apr 18, 2001
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch #416953: Cache ASCII characters to speed up ASCII decoding.
parent
71a75288
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
0 deletions
+33
-0
Objects/unicodeobject.c
Objects/unicodeobject.c
+33
-0
No files found.
Objects/unicodeobject.c
View file @
dfb39758
...
...
@@ -90,6 +90,8 @@ static PyUnicodeObject *unicode_empty;
static
PyUnicodeObject
*
unicode_freelist
;
static
int
unicode_freelist_size
;
static
PyUnicodeObject
*
unicode_ascii
[
128
];
/* Default encoding to use and assume when NULL is passed as encoding
parameter; it is initialized by _PyUnicode_Init().
...
...
@@ -251,6 +253,19 @@ PyObject *PyUnicode_FromUnicode(const Py_UNICODE *u,
{
PyUnicodeObject
*
unicode
;
if
(
size
==
1
&&
*
u
<
128
)
{
unicode
=
unicode_ascii
[
*
u
];
if
(
!
unicode
)
{
unicode
=
_PyUnicode_New
(
1
);
unicode
->
str
[
0
]
=
*
u
;
if
(
!
unicode
)
return
NULL
;
unicode_ascii
[
*
u
]
=
unicode
;
}
Py_INCREF
(
unicode
);
return
(
PyObject
*
)
unicode
;
}
unicode
=
_PyUnicode_New
(
size
);
if
(
!
unicode
)
return
NULL
;
...
...
@@ -1656,6 +1671,11 @@ PyObject *PyUnicode_DecodeASCII(const char *s,
PyUnicodeObject
*
v
;
Py_UNICODE
*
p
;
if
(
size
==
1
&&
*
(
unsigned
char
*
)
s
<
128
)
{
Py_UNICODE
r
=
*
(
unsigned
char
*
)
s
;
return
PyUnicode_FromUnicode
(
&
r
,
1
);
}
/* ASCII is equivalent to the first 128 ordinals in Unicode. */
v
=
_PyUnicode_New
(
size
);
if
(
v
==
NULL
)
...
...
@@ -5189,6 +5209,8 @@ PyTypeObject PyUnicode_Type = {
void
_PyUnicode_Init
(
void
)
{
int
i
;
/* Doublecheck the configuration... */
if
(
sizeof
(
Py_UNICODE
)
!=
2
)
Py_FatalError
(
"Unicode configuration error: "
...
...
@@ -5199,6 +5221,9 @@ void _PyUnicode_Init(void)
unicode_freelist_size
=
0
;
unicode_empty
=
_PyUnicode_New
(
0
);
strcpy
(
unicode_default_encoding
,
"ascii"
);
for
(
i
=
0
;
i
<
128
;
i
++
)
unicode_ascii
[
i
]
=
NULL
;
}
/* Finalize the Unicode implementation */
...
...
@@ -5207,10 +5232,18 @@ void
_PyUnicode_Fini
(
void
)
{
PyUnicodeObject
*
u
;
int
i
;
Py_XDECREF
(
unicode_empty
);
unicode_empty
=
NULL
;
for
(
i
=
0
;
i
<
128
;
i
++
)
{
if
(
unicode_ascii
[
i
])
{
Py_DECREF
(
unicode_ascii
[
i
]);
unicode_ascii
[
i
]
=
NULL
;
}
}
for
(
u
=
unicode_freelist
;
u
!=
NULL
;)
{
PyUnicodeObject
*
v
=
u
;
u
=
*
(
PyUnicodeObject
**
)
u
;
...
...
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