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
f8de4f1a
Commit
f8de4f1a
authored
May 27, 2014
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cut down on unnecessary string copies
parent
6eb1b53f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
40 deletions
+44
-40
src/analysis/type_analysis.cpp
src/analysis/type_analysis.cpp
+4
-5
src/core/ast.cpp
src/core/ast.cpp
+33
-27
src/core/ast.h
src/core/ast.h
+4
-0
src/core/types.h
src/core/types.h
+0
-5
src/runtime/objmodel.cpp
src/runtime/objmodel.cpp
+3
-3
No files found.
src/analysis/type_analysis.cpp
View file @
f8de4f1a
...
...
@@ -202,8 +202,7 @@ private:
CompilerType
*
right
=
getType
(
node
->
right
);
// TODO this isn't the exact behavior
std
::
string
name
=
getOpName
(
node
->
op_type
);
name
=
"__i"
+
name
.
substr
(
2
);
std
::
string
name
=
getInplaceOpName
(
node
->
op_type
);
CompilerType
*
attr_type
=
left
->
getattrType
(
&
name
,
true
);
if
(
attr_type
==
UNDEF
)
...
...
@@ -230,7 +229,7 @@ private:
CompilerType
*
right
=
getType
(
node
->
right
);
// TODO this isn't the exact behavior
std
::
string
name
=
getOpName
(
node
->
op_type
);
const
std
::
string
&
name
=
getOpName
(
node
->
op_type
);
CompilerType
*
attr_type
=
left
->
getattrType
(
&
name
,
true
);
if
(
attr_type
==
UNDEF
)
...
...
@@ -304,7 +303,7 @@ private:
return
BOOL
;
}
std
::
string
name
=
getOpName
(
node
->
ops
[
0
]);
const
std
::
string
&
name
=
getOpName
(
node
->
ops
[
0
]);
CompilerType
*
attr_type
=
left
->
getattrType
(
&
name
,
true
);
if
(
attr_type
==
UNDEF
)
...
...
@@ -409,7 +408,7 @@ private:
CompilerType
*
operand
=
getType
(
node
->
operand
);
// TODO this isn't the exact behavior
std
::
string
name
=
getOpName
(
node
->
op_type
);
const
std
::
string
&
name
=
getOpName
(
node
->
op_type
);
CompilerType
*
attr_type
=
operand
->
getattrType
(
&
name
,
true
);
std
::
vector
<
CompilerType
*>
arg_types
;
return
attr_type
->
callType
(
arg_types
);
...
...
src/core/ast.cpp
View file @
f8de4f1a
...
...
@@ -90,60 +90,66 @@ std::string getInplaceOpSymbol(int op_type) {
return
std
::
string
(
getOpSymbol
(
op_type
))
+
'='
;
}
std
::
string
getOpName
(
int
op_type
)
{
const
static
std
::
string
strAdd
(
"__add__"
),
strBitAnd
(
"__and__"
),
strBitOr
(
"__or__"
),
strBitXor
(
"__xor__"
),
strDiv
(
"__div__"
),
strTrueDiv
(
"__truediv__"
),
strEq
(
"__eq__"
),
strFloorDiv
(
"__floordiv__"
),
strLShift
(
"__lshift__"
),
strLt
(
"__lt__"
),
strLtE
(
"__le__"
),
strGt
(
"__gt__"
),
strGtE
(
"__ge__"
),
strIn
(
"__contains__"
),
strInvert
(
"__invert__"
),
strMod
(
"__mod__"
),
strMult
(
"__mul__"
),
strNot
(
"__nonzero__"
),
strNotEq
(
"__ne__"
),
strPow
(
"__pow__"
),
strRShift
(
"__rshift__"
),
strSub
(
"__sub__"
),
strUAdd
(
"__pos__"
),
strUSub
(
"__neg__"
);
const
std
::
string
&
getOpName
(
int
op_type
)
{
assert
(
op_type
!=
AST_TYPE
::
Is
);
assert
(
op_type
!=
AST_TYPE
::
IsNot
);
switch
(
op_type
)
{
case
AST_TYPE
:
:
Add
:
return
"__add__"
;
return
strAdd
;
case
AST_TYPE
:
:
BitAnd
:
return
"__and__"
;
return
strBitAnd
;
case
AST_TYPE
:
:
BitOr
:
return
"__or__"
;
return
strBitOr
;
case
AST_TYPE
:
:
BitXor
:
return
"__xor__"
;
return
strBitXor
;
case
AST_TYPE
:
:
Div
:
if
(
FUTURE_DIVISION
)
return
"__truediv__"
;
return
strTrueDiv
;
else
return
"__div__"
;
return
strDiv
;
case
AST_TYPE
:
:
Eq
:
return
"__eq__"
;
return
strEq
;
case
AST_TYPE
:
:
FloorDiv
:
return
"__floordiv__"
;
return
strFloorDiv
;
case
AST_TYPE
:
:
LShift
:
return
"__lshift__"
;
return
strLShift
;
case
AST_TYPE
:
:
Lt
:
return
"__lt__"
;
return
strLt
;
case
AST_TYPE
:
:
LtE
:
return
"__le__"
;
return
strLtE
;
case
AST_TYPE
:
:
Gt
:
return
"__gt__"
;
return
strGt
;
case
AST_TYPE
:
:
GtE
:
return
"__ge__"
;
return
strGtE
;
case
AST_TYPE
:
:
In
:
return
"__contains__"
;
return
strIn
;
case
AST_TYPE
:
:
Invert
:
return
"__invert__"
;
return
strInvert
;
case
AST_TYPE
:
:
Mod
:
return
"__mod__"
;
return
strMod
;
case
AST_TYPE
:
:
Mult
:
return
"__mul__"
;
return
strMult
;
case
AST_TYPE
:
:
Not
:
return
"__nonzero__"
;
return
strNot
;
case
AST_TYPE
:
:
NotEq
:
return
"__ne__"
;
return
strNotEq
;
case
AST_TYPE
:
:
Pow
:
return
"__pow__"
;
return
strPow
;
case
AST_TYPE
:
:
RShift
:
return
"__rshift__"
;
return
strRShift
;
case
AST_TYPE
:
:
Sub
:
return
"__sub__"
;
return
strSub
;
case
AST_TYPE
:
:
UAdd
:
return
"__pos__"
;
return
strUAdd
;
case
AST_TYPE
:
:
USub
:
return
"__neg__"
;
return
strUSub
;
default:
fprintf
(
stderr
,
"Unknown op type ("
__FILE__
":"
STRINGIFY
(
__LINE__
)
"): %d
\n
"
,
op_type
);
abort
();
...
...
@@ -151,7 +157,7 @@ std::string getOpName(int op_type) {
}
std
::
string
getInplaceOpName
(
int
op_type
)
{
std
::
string
normal_name
=
getOpName
(
op_type
);
const
std
::
string
&
normal_name
=
getOpName
(
op_type
);
return
"__i"
+
normal_name
.
substr
(
2
);
}
...
...
@@ -172,7 +178,7 @@ std::string getReverseOpName(int op_type) {
if
(
op_type
==
AST_TYPE
::
Eq
)
return
getOpName
(
AST_TYPE
::
Eq
);
std
::
string
normal_name
=
getOpName
(
op_type
);
const
std
::
string
&
normal_name
=
getOpName
(
op_type
);
return
"__r"
+
normal_name
.
substr
(
2
);
}
...
...
src/core/ast.h
View file @
f8de4f1a
...
...
@@ -1114,6 +1114,10 @@ template <class T, class R> void findNodes(const R& roots, std::vector<T*>& outp
}
llvm
::
StringRef
getOpSymbol
(
int
op_type
);
const
std
::
string
&
getOpName
(
int
op_type
);
std
::
string
getReverseOpName
(
int
op_type
);
std
::
string
getInplaceOpName
(
int
op_type
);
std
::
string
getInplaceOpSymbol
(
int
op_type
);
};
#endif
src/core/types.h
View file @
f8de4f1a
...
...
@@ -227,11 +227,6 @@ CLFunction* unboxRTFunction(Box*);
extern
"C"
CompiledFunction
*
resolveCLFunc
(
CLFunction
*
f
,
int64_t
nargs
,
Box
*
arg1
,
Box
*
arg2
,
Box
*
arg3
,
Box
**
args
);
extern
"C"
Box
*
callCompiledFunc
(
CompiledFunction
*
cf
,
int64_t
nargs
,
Box
*
arg1
,
Box
*
arg2
,
Box
*
arg3
,
Box
**
args
);
std
::
string
getOpName
(
int
op_type
);
std
::
string
getReverseOpName
(
int
op_type
);
std
::
string
getInplaceOpName
(
int
op_type
);
std
::
string
getInplaceOpSymbol
(
int
op_type
);
typedef
bool
i1
;
typedef
int64_t
i64
;
...
...
src/runtime/objmodel.cpp
View file @
f8de4f1a
...
...
@@ -1740,7 +1740,7 @@ extern "C" Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, Bin
std
::
string
op_name
=
getOpName
(
op_type
);
const
std
::
string
&
op_name
=
getOpName
(
op_type
);
Box
*
lrtn
;
if
(
rewrite_args
)
{
CallRewriteArgs
srewrite_args
(
rewrite_args
->
rewriter
,
rewrite_args
->
lhs
);
...
...
@@ -1938,7 +1938,7 @@ Box* compareInternal(Box* lhs, Box* rhs, int op_type, CompareRewriteArgs* rewrit
rewrite_args
->
rhs
.
addAttrGuard
(
BOX_CLS_OFFSET
,
(
intptr_t
)
rhs
->
cls
);
}
std
::
string
op_name
=
getOpName
(
op_type
);
const
std
::
string
&
op_name
=
getOpName
(
op_type
);
Box
*
lrtn
;
if
(
rewrite_args
)
{
...
...
@@ -2049,7 +2049,7 @@ extern "C" Box* unaryop(Box* operand, int op_type) {
static
StatCounter
slowpath_unaryop
(
"slowpath_unaryop"
);
slowpath_unaryop
.
log
();
std
::
string
op_name
=
getOpName
(
op_type
);
const
std
::
string
&
op_name
=
getOpName
(
op_type
);
Box
*
attr_func
=
getclsattr_internal
(
operand
,
op_name
,
NULL
,
NULL
);
...
...
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