Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Boxiang Sun
Pyston
Commits
4f9fa37b
Commit
4f9fa37b
authored
May 18, 2016
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some likely/unlikely annotations to _PyUnicode_New
parent
261d33c0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
5 deletions
+8
-5
from_cpython/Objects/unicodeobject.c
from_cpython/Objects/unicodeobject.c
+8
-5
No files found.
from_cpython/Objects/unicodeobject.c
View file @
4f9fa37b
...
...
@@ -51,6 +51,9 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <windows.h>
#endif
#define UNLIKELY(value) __builtin_expect((value), 0)
#define LIKELY(value) __builtin_expect((value), 1)
/* Limit for the Unicode object free list */
#define PyUnicode_MAXFREELIST 1024
...
...
@@ -321,22 +324,22 @@ PyUnicodeObject *_PyUnicode_New(Py_ssize_t length)
register
PyUnicodeObject
*
unicode
;
/* Optimization for empty strings */
if
(
length
==
0
&&
unicode_empty
!=
NULL
)
{
if
(
UNLIKELY
(
length
==
0
&&
unicode_empty
!=
NULL
)
)
{
Py_INCREF
(
unicode_empty
);
return
unicode_empty
;
}
/* Ensure we won't overflow the size. */
if
(
length
>
((
PY_SSIZE_T_MAX
/
sizeof
(
Py_UNICODE
))
-
1
))
{
if
(
UNLIKELY
(
length
>
((
PY_SSIZE_T_MAX
/
sizeof
(
Py_UNICODE
))
-
1
)
))
{
return
(
PyUnicodeObject
*
)
PyErr_NoMemory
();
}
/* Unicode freelist & memory allocation */
if
(
free_list
)
{
if
(
LIKELY
((
intptr_t
)
free_list
)
)
{
unicode
=
free_list
;
free_list
=
*
(
PyUnicodeObject
**
)
unicode
;
numfree
--
;
if
(
unicode
->
str
)
{
if
(
(
intptr_t
)
unicode
->
str
)
{
/* Keep-Alive optimization: we only upsize the buffer,
never downsize it. */
if
((
unicode
->
length
<
length
)
&&
...
...
@@ -360,7 +363,7 @@ PyUnicodeObject *_PyUnicode_New(Py_ssize_t length)
unicode
->
str
=
(
Py_UNICODE
*
)
PyObject_MALLOC
(
new_size
);
}
if
(
!
unicode
->
str
)
{
if
(
UNLIKELY
(
!
unicode
->
str
)
)
{
PyErr_NoMemory
();
goto
onError
;
}
...
...
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