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
51b19ce0
Commit
51b19ce0
authored
Aug 10, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #819 from kmod/perf3
microoptimizations
parents
a71a661f
7df9e626
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
6 deletions
+31
-6
src/runtime/bool.cpp
src/runtime/bool.cpp
+7
-2
src/runtime/str.cpp
src/runtime/str.cpp
+24
-4
No files found.
src/runtime/bool.cpp
View file @
51b19ce0
...
...
@@ -39,8 +39,12 @@ extern "C" Box* boolRepr(BoxedBool* v) {
return
false_str
;
}
extern
"C"
Box
*
boolHash
(
BoxedBool
*
v
)
{
return
boxInt
(
v
==
True
);
size_t
bool_hash
(
BoxedBool
*
v
)
{
return
v
==
True
;
}
Box
*
boolHash
(
BoxedBool
*
v
)
{
return
boxInt
(
bool_hash
(
v
));
}
extern
"C"
Box
*
boolNew
(
Box
*
cls
,
Box
*
val
)
{
...
...
@@ -96,6 +100,7 @@ void setupBool() {
bool_cls
->
giveAttr
(
"__xor__"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
boolXor
,
BOXED_BOOL
,
2
)));
bool_cls
->
freeze
();
bool_cls
->
tp_hash
=
(
hashfunc
)
bool_hash
;
}
void
teardownBool
()
{
...
...
src/runtime/str.cpp
View file @
51b19ce0
...
...
@@ -1584,7 +1584,11 @@ extern "C" size_t strHashUnboxed(BoxedString* self) {
}
extern
"C"
Box
*
strHash
(
BoxedString
*
self
)
{
return
boxLong
(
strHashUnboxed
(
self
));
return
boxInt
(
strHashUnboxed
(
self
));
}
size_t
str_hash
(
BoxedString
*
self
)
noexcept
{
return
strHashUnboxed
(
self
);
}
extern
"C"
Box
*
strNonzero
(
BoxedString
*
self
)
{
...
...
@@ -1827,8 +1831,14 @@ Box* strReplace(Box* _self, Box* _old, Box* _new, Box** _args) {
int
max_replaces
=
static_cast
<
BoxedInt
*>
(
_maxreplace
)
->
n
;
size_t
start_pos
=
0
;
std
::
string
s
=
self
->
s
();
bool
single_char
=
old
->
size
()
==
1
;
for
(
int
num_replaced
=
0
;
num_replaced
<
max_replaces
||
max_replaces
<
0
;
++
num_replaced
)
{
start_pos
=
s
.
find
(
old
->
s
(),
start_pos
);
if
(
single_char
)
start_pos
=
s
.
find
(
old
->
s
()[
0
],
start_pos
);
else
start_pos
=
s
.
find
(
old
->
s
(),
start_pos
);
if
(
start_pos
==
std
::
string
::
npos
)
break
;
s
.
replace
(
start_pos
,
old
->
size
(),
new_
->
s
());
...
...
@@ -1841,7 +1851,11 @@ Box* strPartition(BoxedString* self, BoxedString* sep) {
RELEASE_ASSERT
(
PyString_Check
(
self
),
""
);
RELEASE_ASSERT
(
PyString_Check
(
sep
),
""
);
size_t
found_idx
=
self
->
s
().
find
(
sep
->
s
());
size_t
found_idx
;
if
(
sep
->
size
()
==
1
)
found_idx
=
self
->
s
().
find
(
sep
->
s
()[
0
]);
else
found_idx
=
self
->
s
().
find
(
sep
->
s
());
if
(
found_idx
==
std
::
string
::
npos
)
return
BoxedTuple
::
create
({
self
,
EmptyString
,
EmptyString
});
...
...
@@ -2063,7 +2077,12 @@ Box* strContains(BoxedString* self, Box* elt) {
BoxedString
*
sub
=
static_cast
<
BoxedString
*>
(
elt
);
size_t
found_idx
=
self
->
s
().
find
(
sub
->
s
());
size_t
found_idx
;
if
(
sub
->
size
()
==
1
)
// Call the much-faster single-character find():
found_idx
=
self
->
s
().
find
(
sub
->
s
()[
0
]);
else
found_idx
=
self
->
s
().
find
(
sub
->
s
());
if
(
found_idx
==
std
::
string
::
npos
)
return
False
;
return
True
;
...
...
@@ -2841,6 +2860,7 @@ void setupStr() {
str_cls
->
tp_as_sequence
->
sq_slice
=
str_slice
;
str_cls
->
tp_as_sequence
->
sq_length
=
str_length
;
str_cls
->
tp_iter
=
(
decltype
(
str_cls
->
tp_iter
))
strIter
;
str_cls
->
tp_hash
=
(
hashfunc
)
str_hash
;
basestring_cls
->
giveAttr
(
"__doc__"
,
boxString
(
"Type basestring cannot be instantiated; it is the base for str and unicode."
));
...
...
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