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
ee7cf48d
Commit
ee7cf48d
authored
Feb 17, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Teach len() howto rewrite itself
-15% for fasta.py
parent
a4722ed0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
1 deletion
+26
-1
src/runtime/builtin_modules/builtins.cpp
src/runtime/builtin_modules/builtins.cpp
+5
-1
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+19
-0
src/runtime/objmodel.h
src/runtime/objmodel.h
+2
-0
No files found.
src/runtime/builtin_modules/builtins.cpp
View file @
ee7cf48d
...
@@ -1048,8 +1048,12 @@ void setupBuiltins() {
...
@@ -1048,8 +1048,12 @@ void setupBuiltins() {
repr_obj
=
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
repr
,
UNKNOWN
,
1
));
repr_obj
=
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
repr
,
UNKNOWN
,
1
));
builtins_module
->
giveAttr
(
"repr"
,
repr_obj
);
builtins_module
->
giveAttr
(
"repr"
,
repr_obj
);
len_obj
=
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
len
,
UNKNOWN
,
1
));
auto
len_func
=
boxRTFunction
((
void
*
)
len
,
UNKNOWN
,
1
);
len_func
->
internal_callable
=
lenCallInternal
;
len_obj
=
new
BoxedBuiltinFunctionOrMethod
(
len_func
);
builtins_module
->
giveAttr
(
"len"
,
len_obj
);
builtins_module
->
giveAttr
(
"len"
,
len_obj
);
hash_obj
=
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
hash
,
UNKNOWN
,
1
));
hash_obj
=
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
hash
,
UNKNOWN
,
1
));
builtins_module
->
giveAttr
(
"hash"
,
hash_obj
);
builtins_module
->
giveAttr
(
"hash"
,
hash_obj
);
abs_obj
=
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
abs_
,
UNKNOWN
,
1
));
abs_obj
=
new
BoxedBuiltinFunctionOrMethod
(
boxRTFunction
((
void
*
)
abs_
,
UNKNOWN
,
1
));
...
...
src/runtime/objmodel.cpp
View file @
ee7cf48d
...
@@ -1900,6 +1900,25 @@ extern "C" BoxedInt* lenInternal(Box* obj, LenRewriteArgs* rewrite_args) {
...
@@ -1900,6 +1900,25 @@ extern "C" BoxedInt* lenInternal(Box* obj, LenRewriteArgs* rewrite_args) {
return
static_cast
<
BoxedInt
*>
(
rtn
);
return
static_cast
<
BoxedInt
*>
(
rtn
);
}
}
Box
*
lenCallInternal
(
BoxedFunctionBase
*
func
,
CallRewriteArgs
*
rewrite_args
,
ArgPassSpec
argspec
,
Box
*
arg1
,
Box
*
arg2
,
Box
*
arg3
,
Box
**
args
,
const
std
::
vector
<
const
std
::
string
*>*
keyword_names
)
{
if
(
argspec
!=
ArgPassSpec
(
1
))
return
callFunc
(
func
,
rewrite_args
,
argspec
,
arg1
,
arg2
,
arg3
,
args
,
keyword_names
);
if
(
rewrite_args
)
{
LenRewriteArgs
lrewrite_args
(
rewrite_args
->
rewriter
,
rewrite_args
->
arg1
,
rewrite_args
->
destination
);
Box
*
rtn
=
lenInternal
(
arg1
,
&
lrewrite_args
);
if
(
!
lrewrite_args
.
out_success
)
{
rewrite_args
=
0
;
}
else
{
rewrite_args
->
out_rtn
=
lrewrite_args
.
out_rtn
;
rewrite_args
->
out_success
=
true
;
}
return
rtn
;
}
return
lenInternal
(
arg1
,
NULL
);
}
extern
"C"
BoxedInt
*
len
(
Box
*
obj
)
{
extern
"C"
BoxedInt
*
len
(
Box
*
obj
)
{
static
StatCounter
slowpath_len
(
"slowpath_len"
);
static
StatCounter
slowpath_len
(
"slowpath_len"
);
slowpath_len
.
log
();
slowpath_len
.
log
();
...
...
src/runtime/objmodel.h
View file @
ee7cf48d
...
@@ -100,6 +100,8 @@ struct BinopRewriteArgs;
...
@@ -100,6 +100,8 @@ struct BinopRewriteArgs;
extern
"C"
Box
*
binopInternal
(
Box
*
lhs
,
Box
*
rhs
,
int
op_type
,
bool
inplace
,
BinopRewriteArgs
*
rewrite_args
);
extern
"C"
Box
*
binopInternal
(
Box
*
lhs
,
Box
*
rhs
,
int
op_type
,
bool
inplace
,
BinopRewriteArgs
*
rewrite_args
);
struct
CallRewriteArgs
;
struct
CallRewriteArgs
;
Box
*
lenCallInternal
(
BoxedFunctionBase
*
f
,
CallRewriteArgs
*
rewrite_args
,
ArgPassSpec
argspec
,
Box
*
arg1
,
Box
*
arg2
,
Box
*
arg3
,
Box
**
args
,
const
std
::
vector
<
const
std
::
string
*>*
keyword_names
);
Box
*
typeCallInternal
(
BoxedFunctionBase
*
f
,
CallRewriteArgs
*
rewrite_args
,
ArgPassSpec
argspec
,
Box
*
arg1
,
Box
*
arg2
,
Box
*
typeCallInternal
(
BoxedFunctionBase
*
f
,
CallRewriteArgs
*
rewrite_args
,
ArgPassSpec
argspec
,
Box
*
arg1
,
Box
*
arg2
,
Box
*
arg3
,
Box
**
args
,
const
std
::
vector
<
const
std
::
string
*>*
keyword_names
);
Box
*
arg3
,
Box
**
args
,
const
std
::
vector
<
const
std
::
string
*>*
keyword_names
);
...
...
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