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
fe26d83a
Commit
fe26d83a
authored
Aug 27, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some random runtime function optimizations
Mostly around trying to avoid calling callattr().
parent
3132de84
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
15 deletions
+60
-15
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+37
-11
src/runtime/dict.cpp
src/runtime/dict.cpp
+23
-4
No files found.
src/runtime/builtin_modules/builtins.cpp
View file @
fe26d83a
...
@@ -250,15 +250,35 @@ extern "C" Box* max(Box* arg0, BoxedTuple* args, BoxedDict* kwargs) {
...
@@ -250,15 +250,35 @@ extern "C" Box* max(Box* arg0, BoxedTuple* args, BoxedDict* kwargs) {
return
maxElement
;
return
maxElement
;
}
}
extern
"C"
Box
*
next
(
Box
*
iterator
,
Box
*
_default
)
{
extern
"C"
Box
*
next
(
Box
*
iterator
,
Box
*
_default
)
noexcept
{
try
{
if
(
!
PyIter_Check
(
iterator
))
{
static
BoxedString
*
next_str
=
internStringImmortal
(
"next"
);
PyErr_Format
(
PyExc_TypeError
,
"%.200s object is not an iterator"
,
iterator
->
cls
->
tp_name
);
CallattrFlags
callattr_flags
{.
cls_only
=
true
,
.
null_on_nonexistent
=
false
,
.
argspec
=
ArgPassSpec
(
0
)
};
return
NULL
;
return
callattr
(
iterator
,
next_str
,
callattr_flags
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
}
}
catch
(
ExcInfo
e
)
{
if
(
_default
&&
e
.
matches
(
StopIteration
))
Box
*
rtn
;
return
_default
;
throw
e
;
if
(
iterator
->
cls
->
tp_iternext
==
slot_tp_iternext
)
{
rtn
=
iterator
->
cls
->
call_nextIC
(
iterator
);
}
else
{
rtn
=
iterator
->
cls
->
tp_iternext
(
iterator
);
}
if
(
rtn
!=
NULL
)
{
return
rtn
;
}
else
if
(
_default
!=
NULL
)
{
if
(
PyErr_Occurred
())
{
if
(
!
PyErr_ExceptionMatches
(
PyExc_StopIteration
))
return
NULL
;
PyErr_Clear
();
}
Py_INCREF
(
_default
);
return
_default
;
}
else
if
(
PyErr_Occurred
())
{
return
NULL
;
}
else
{
PyErr_SetNone
(
PyExc_StopIteration
);
return
NULL
;
}
}
}
}
...
@@ -1248,6 +1268,11 @@ Box* print(BoxedTuple* args, BoxedDict* kwargs) {
...
@@ -1248,6 +1268,11 @@ Box* print(BoxedTuple* args, BoxedDict* kwargs) {
Box
*
getreversed
(
Box
*
o
)
{
Box
*
getreversed
(
Box
*
o
)
{
static
BoxedString
*
reversed_str
=
internStringImmortal
(
"__reversed__"
);
static
BoxedString
*
reversed_str
=
internStringImmortal
(
"__reversed__"
);
// common case:
if
(
o
->
cls
==
list_cls
)
{
return
listReversed
(
o
);
}
// TODO add rewriting to this? probably want to try to avoid this path though
// TODO add rewriting to this? probably want to try to avoid this path though
CallattrFlags
callattr_flags
{.
cls_only
=
true
,
.
null_on_nonexistent
=
true
,
.
argspec
=
ArgPassSpec
(
0
)
};
CallattrFlags
callattr_flags
{.
cls_only
=
true
,
.
null_on_nonexistent
=
true
,
.
argspec
=
ArgPassSpec
(
0
)
};
Box
*
r
=
callattr
(
o
,
reversed_str
,
callattr_flags
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
Box
*
r
=
callattr
(
o
,
reversed_str
,
callattr_flags
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
...
@@ -1514,8 +1539,9 @@ void setupBuiltins() {
...
@@ -1514,8 +1539,9 @@ void setupBuiltins() {
max_obj
=
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
max
,
UNKNOWN
,
1
,
1
,
true
,
true
),
"max"
,
{
None
});
max_obj
=
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
max
,
UNKNOWN
,
1
,
1
,
true
,
true
),
"max"
,
{
None
});
builtins_module
->
giveAttr
(
"max"
,
max_obj
);
builtins_module
->
giveAttr
(
"max"
,
max_obj
);
builtins_module
->
giveAttr
(
"next"
,
new
BoxedBuiltinFunctionOrMethod
(
builtins_module
->
giveAttr
(
"next"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
next
,
UNKNOWN
,
2
,
1
,
false
,
boxRTFunction
((
void
*
)
next
,
UNKNOWN
,
2
,
1
,
false
,
false
),
"next"
,
{
NULL
}));
false
,
ParamNames
::
empty
(),
CAPI
),
"next"
,
{
NULL
}));
builtins_module
->
giveAttr
(
"sum"
,
new
BoxedBuiltinFunctionOrMethod
(
builtins_module
->
giveAttr
(
"sum"
,
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
sum
,
UNKNOWN
,
2
,
1
,
false
,
false
),
"sum"
,
{
boxInt
(
0
)
}));
boxRTFunction
((
void
*
)
sum
,
UNKNOWN
,
2
,
1
,
false
,
false
),
"sum"
,
{
boxInt
(
0
)
}));
...
...
src/runtime/dict.cpp
View file @
fe26d83a
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#include "core/stats.h"
#include "core/stats.h"
#include "core/types.h"
#include "core/types.h"
#include "gc/collector.h"
#include "gc/collector.h"
#include "runtime/ics.h"
#include "runtime/inline/list.h"
#include "runtime/inline/list.h"
#include "runtime/objmodel.h"
#include "runtime/objmodel.h"
#include "runtime/types.h"
#include "runtime/types.h"
...
@@ -238,11 +239,24 @@ template <enum ExceptionStyle S> Box* dictGetitem(BoxedDict* self, Box* k) noexc
...
@@ -238,11 +239,24 @@ template <enum ExceptionStyle S> Box* dictGetitem(BoxedDict* self, Box* k) noexc
if
(
it
==
self
->
d
.
end
())
{
if
(
it
==
self
->
d
.
end
())
{
// Try calling __missing__ if this is a subclass
// Try calling __missing__ if this is a subclass
if
(
self
->
cls
!=
dict_cls
)
{
if
(
self
->
cls
!=
dict_cls
)
{
// Special-case defaultdict, assuming that it's the main time we will actually hit this.
// We could just use a single runtime IC here, or have a small cache that maps type->runtimeic.
// Or use a polymorphic runtime ic.
static
BoxedClass
*
defaultdict_cls
=
NULL
;
static
CallattrIC
defaultdict_ic
;
if
(
defaultdict_cls
==
NULL
&&
strcmp
(
self
->
cls
->
tp_name
,
"collections.defaultdict"
)
==
0
)
{
defaultdict_cls
=
self
->
cls
;
}
static
BoxedString
*
missing_str
=
internStringImmortal
(
"__missing__"
);
static
BoxedString
*
missing_str
=
internStringImmortal
(
"__missing__"
);
CallattrFlags
callattr_flags
{.
cls_only
=
true
,
.
null_on_nonexistent
=
true
,
.
argspec
=
ArgPassSpec
(
1
)
};
CallattrFlags
callattr_flags
{.
cls_only
=
true
,
.
null_on_nonexistent
=
true
,
.
argspec
=
ArgPassSpec
(
1
)
};
Box
*
r
;
Box
*
r
;
try
{
try
{
r
=
callattr
(
self
,
missing_str
,
callattr_flags
,
k
,
NULL
,
NULL
,
NULL
,
NULL
);
if
(
self
->
cls
==
defaultdict_cls
)
{
r
=
defaultdict_ic
.
call
(
self
,
missing_str
,
callattr_flags
,
k
,
NULL
,
NULL
,
NULL
,
NULL
);
}
else
{
r
=
callattr
(
self
,
missing_str
,
callattr_flags
,
k
,
NULL
,
NULL
,
NULL
,
NULL
);
}
}
catch
(
ExcInfo
e
)
{
}
catch
(
ExcInfo
e
)
{
if
(
S
==
CAPI
)
{
if
(
S
==
CAPI
)
{
setCAPIException
(
e
);
setCAPIException
(
e
);
...
@@ -603,9 +617,14 @@ void dictMerge(BoxedDict* self, Box* other) {
...
@@ -603,9 +617,14 @@ void dictMerge(BoxedDict* self, Box* other) {
return
;
return
;
}
}
static
BoxedString
*
keys_str
=
internStringImmortal
(
"keys"
);
Box
*
keys
;
CallattrFlags
callattr_flags
{.
cls_only
=
false
,
.
null_on_nonexistent
=
true
,
.
argspec
=
ArgPassSpec
(
0
)
};
if
(
other
->
cls
==
attrwrapper_cls
)
{
Box
*
keys
=
callattr
(
other
,
keys_str
,
callattr_flags
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
keys
=
attrwrapperKeys
(
other
);
}
else
{
static
BoxedString
*
keys_str
=
internStringImmortal
(
"keys"
);
CallattrFlags
callattr_flags
{.
cls_only
=
false
,
.
null_on_nonexistent
=
true
,
.
argspec
=
ArgPassSpec
(
0
)
};
keys
=
callattr
(
other
,
keys_str
,
callattr_flags
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
);
}
assert
(
keys
);
assert
(
keys
);
for
(
Box
*
k
:
keys
->
pyElements
())
{
for
(
Box
*
k
:
keys
->
pyElements
())
{
...
...
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