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
634950ff
Commit
634950ff
authored
Jun 16, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #615 from kmod/sre_compile3
Optimize creating tuples from lists
parents
424539a1
d1da6f57
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
6 deletions
+35
-6
microbenchmarks/sre_optimize_unicode.py
microbenchmarks/sre_optimize_unicode.py
+11
-0
microbenchmarks/tuple_ubench.py
microbenchmarks/tuple_ubench.py
+4
-0
src/runtime/tuple.cpp
src/runtime/tuple.cpp
+10
-1
test/tests/sre_compile_test.py
test/tests/sre_compile_test.py
+10
-5
No files found.
microbenchmarks/sre_optimize_unicode.py
0 → 100644
View file @
634950ff
import
sre_compile
import
sre_constants
def
identity
(
o
):
return
o
charset
=
[(
sre_constants
.
RANGE
,
(
128
,
65535
))]
for
i
in
xrange
(
100
):
sre_compile
.
_optimize_unicode
(
charset
,
identity
)
# print sre_compile._optimize_charset(charset, identity)
microbenchmarks/tuple_ubench.py
0 → 100644
View file @
634950ff
l
=
range
(
256
)
for
i
in
xrange
(
200000
):
tuple
(
l
)
src/runtime/tuple.cpp
View file @
634950ff
...
@@ -135,7 +135,7 @@ int BoxedTuple::Resize(BoxedTuple** pv, size_t newsize) noexcept {
...
@@ -135,7 +135,7 @@ int BoxedTuple::Resize(BoxedTuple** pv, size_t newsize) noexcept {
BoxedTuple
*
resized
=
new
(
newsize
)
BoxedTuple
*
resized
=
new
(
newsize
)
BoxedTuple
(
newsize
);
// we want an uninitialized tuple, but this will memset it with 0.
BoxedTuple
(
newsize
);
// we want an uninitialized tuple, but this will memset it with 0.
memmove
(
resized
->
elts
,
t
->
elts
,
t
->
size
());
memmove
(
resized
->
elts
,
t
->
elts
,
sizeof
(
Box
*
)
*
t
->
size
());
*
pv
=
resized
;
*
pv
=
resized
;
return
0
;
return
0
;
...
@@ -286,6 +286,15 @@ extern "C" Box* tupleNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) {
...
@@ -286,6 +286,15 @@ extern "C" Box* tupleNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) {
raiseExcHelper
(
TypeError
,
"'%s' is an invalid keyword argument for this function"
,
kw
->
data
());
raiseExcHelper
(
TypeError
,
"'%s' is an invalid keyword argument for this function"
,
kw
->
data
());
}
}
if
(
cls
==
tuple_cls
)
{
// Call PySequence_Tuple since it has some perf special-cases
// that can make it quite a bit faster than the generic pyElements iteration:
Box
*
r
=
PySequence_Tuple
(
elements
);
if
(
!
r
)
throwCAPIException
();
return
r
;
}
std
::
vector
<
Box
*
,
StlCompatAllocator
<
Box
*>>
elts
;
std
::
vector
<
Box
*
,
StlCompatAllocator
<
Box
*>>
elts
;
for
(
auto
e
:
elements
->
pyElements
())
for
(
auto
e
:
elements
->
pyElements
())
elts
.
push_back
(
e
);
elts
.
push_back
(
e
);
...
...
test/tests/sre_compile_test.py
View file @
634950ff
# skip-if: True
# This test works but 1) is very slow [the importing is, not the regex itself], and 2) throws warnings
# This test also seems to leak a lot of memory.
import
sre_compile
import
sre_compile
import
sre_constants
r
=
sre_compile
.
compile
(
"a(b+)c"
,
0
)
r
=
sre_compile
.
compile
(
"a(b+)c"
,
0
)
print
r
.
match
(
""
)
print
r
.
match
(
""
)
print
r
.
match
(
"ac"
)
print
r
.
match
(
"ac"
)
print
r
.
match
(
"abc"
).
groups
()
print
r
.
match
(
"abc"
).
groups
()
for
i
in
xrange
(
100000
):
for
i
in
xrange
(
100000
):
r
.
match
(
"abbc"
).
groups
()
r
.
match
(
"abbc"
).
groups
()
if
i
%
1000
==
0
:
if
i
%
1000
0
==
0
:
print
i
print
i
def
identity
(
o
):
return
o
charset
=
[(
sre_constants
.
RANGE
,
(
128
,
65535
))]
print
sre_compile
.
_optimize_charset
(
charset
,
identity
)
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