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
180192b5
Commit
180192b5
authored
Jul 08, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Speed up len(unicode)
parent
e7b2b337
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
1 deletion
+31
-1
src/capi/typeobject.cpp
src/capi/typeobject.cpp
+1
-1
src/capi/typeobject.h
src/capi/typeobject.h
+1
-0
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+29
-0
No files found.
src/capi/typeobject.cpp
View file @
180192b5
...
...
@@ -1006,7 +1006,7 @@ PyObject* slot_sq_item(PyObject* self, Py_ssize_t i) noexcept {
}
}
static
Py_ssize_t
slot_sq_length
(
PyObject
*
self
)
noexcept
{
/* Pyston change: static */
Py_ssize_t
slot_sq_length
(
PyObject
*
self
)
noexcept
{
STAT_TIMER
(
t0
,
"us_timer_slot_sqlength"
,
SLOT_AVOIDABILITY
(
self
));
static
PyObject
*
len_str
;
...
...
src/capi/typeobject.h
View file @
180192b5
...
...
@@ -39,6 +39,7 @@ PyObject* slot_tp_iternext(PyObject* self) noexcept;
PyObject
*
slot_tp_new
(
PyTypeObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
noexcept
;
PyObject
*
slot_mp_subscript
(
PyObject
*
self
,
PyObject
*
arg1
)
noexcept
;
int
slot_sq_contains
(
PyObject
*
self
,
PyObject
*
value
)
noexcept
;
Py_ssize_t
slot_sq_length
(
PyObject
*
self
)
noexcept
;
}
#endif
src/runtime/objmodel.cpp
View file @
180192b5
...
...
@@ -2422,6 +2422,35 @@ extern "C" BoxedInt* hash(Box* obj) {
extern
"C"
BoxedInt
*
lenInternal
(
Box
*
obj
,
LenRewriteArgs
*
rewrite_args
)
{
static
BoxedString
*
len_str
=
static_cast
<
BoxedString
*>
(
PyString_InternFromString
(
"__len__"
));
// Corresponds to the first part of PyObject_Size:
PySequenceMethods
*
m
=
obj
->
cls
->
tp_as_sequence
;
if
(
m
!=
NULL
&&
m
->
sq_length
!=
NULL
&&
m
->
sq_length
!=
slot_sq_length
)
{
if
(
rewrite_args
)
{
RewriterVar
*
r_obj
=
rewrite_args
->
obj
;
RewriterVar
*
r_cls
=
r_obj
->
getAttr
(
offsetof
(
Box
,
cls
));
RewriterVar
*
r_m
=
r_cls
->
getAttr
(
offsetof
(
BoxedClass
,
tp_as_sequence
));
r_m
->
addGuardNotEq
(
0
);
// Currently, guard that the value of sq_length didn't change, and then
// emit a call to the current function address.
// It might be better to just load the current value of sq_length and call it
// (after guarding it's not null), or maybe not. But the rewriter doesn't currently
// support calling a RewriterVar (can only call fixed function addresses).
r_m
->
addAttrGuard
(
offsetof
(
PySequenceMethods
,
sq_length
),
(
intptr_t
)
m
->
sq_length
);
RewriterVar
*
r_n
=
rewrite_args
->
rewriter
->
call
(
true
,
(
void
*
)
m
->
sq_length
,
r_obj
);
rewrite_args
->
rewriter
->
call
(
true
,
(
void
*
)
checkAndThrowCAPIException
);
RewriterVar
*
r_r
=
rewrite_args
->
rewriter
->
call
(
false
,
(
void
*
)
boxInt
,
r_n
);
rewrite_args
->
out_success
=
true
;
rewrite_args
->
out_rtn
=
r_r
;
}
int
r
=
(
*
m
->
sq_length
)(
obj
);
if
(
r
==
-
1
)
throwCAPIException
();
return
(
BoxedInt
*
)
boxInt
(
r
);
}
Box
*
rtn
;
if
(
rewrite_args
)
{
CallRewriteArgs
crewrite_args
(
rewrite_args
->
rewriter
,
rewrite_args
->
obj
,
rewrite_args
->
destination
);
...
...
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