Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
91525792
Commit
91525792
authored
Dec 20, 2008
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some profiler guided streamlining in compiler output writers
parent
f630bc37
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
21 deletions
+29
-21
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+12
-6
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+3
-2
Cython/StringIOTree.py
Cython/StringIOTree.py
+14
-13
No files found.
Cython/Compiler/Code.py
View file @
91525792
...
@@ -603,12 +603,18 @@ class CCodeWriter(object):
...
@@ -603,12 +603,18 @@ class CCodeWriter(object):
def
put
(
self
,
code
):
def
put
(
self
,
code
):
fix_indent
=
False
fix_indent
=
False
dl
=
code
.
count
(
"{"
)
-
code
.
count
(
"}"
)
if
"{"
in
code
:
if
dl
<
0
:
dl
=
code
.
count
(
"{"
)
self
.
level
+=
dl
else
:
elif
dl
==
0
and
code
.
startswith
(
'}'
):
dl
=
0
fix_indent
=
True
if
"}"
in
code
:
self
.
level
-=
1
dl
-=
code
.
count
(
"}"
)
if
dl
<
0
:
self
.
level
+=
dl
elif
dl
==
0
and
code
[
0
]
==
"}"
:
# special cases like "} else {" need a temporary dedent
fix_indent
=
True
self
.
level
-=
1
if
self
.
bol
:
if
self
.
bol
:
self
.
indent
()
self
.
indent
()
self
.
write
(
code
)
self
.
write
(
code
)
...
...
Cython/Compiler/Nodes.py
View file @
91525792
...
@@ -156,12 +156,13 @@ class Node(object):
...
@@ -156,12 +156,13 @@ class Node(object):
self
.
body
.
annotate
(
code
)
self
.
body
.
annotate
(
code
)
def
end_pos
(
self
):
def
end_pos
(
self
):
if
not
self
.
child_attrs
:
return
self
.
pos
try
:
try
:
return
self
.
_end_pos
return
self
.
_end_pos
except
AttributeError
:
except
AttributeError
:
pos
=
self
.
pos
pos
=
self
.
pos
if
not
self
.
child_attrs
:
self
.
_end_pos
=
pos
return
pos
for
attr
in
self
.
child_attrs
:
for
attr
in
self
.
child_attrs
:
child
=
getattr
(
self
,
attr
)
child
=
getattr
(
self
,
attr
)
# Sometimes lists, sometimes nodes
# Sometimes lists, sometimes nodes
...
...
Cython/StringIOTree.py
View file @
91525792
...
@@ -7,31 +7,32 @@ class StringIOTree(object):
...
@@ -7,31 +7,32 @@ class StringIOTree(object):
def
__init__
(
self
,
stream
=
None
):
def
__init__
(
self
,
stream
=
None
):
self
.
prepended_children
=
[]
self
.
prepended_children
=
[]
self
.
stream
=
stream
# if set to None, it will be constructed on first write
if
stream
is
None
:
stream
=
StringIO
()
self
.
stream
=
stream
self
.
write
=
stream
.
write
def
getvalue
(
self
):
def
getvalue
(
self
):
return
(
""
.
join
([
x
.
getvalue
()
for
x
in
self
.
prepended_children
])
+
content
=
[
x
.
getvalue
()
for
x
in
self
.
prepended_children
]
self
.
stream
.
getvalue
())
content
.
append
(
self
.
stream
.
getvalue
())
return
""
.
join
(
content
)
def
copyto
(
self
,
target
):
def
copyto
(
self
,
target
):
"""Potentially cheaper than getvalue as no string concatenation
"""Potentially cheaper than getvalue as no string concatenation
needs to happen."""
needs to happen."""
for
child
in
self
.
prepended_children
:
for
child
in
self
.
prepended_children
:
child
.
copyto
(
target
)
child
.
copyto
(
target
)
if
self
.
stream
:
stream_content
=
self
.
stream
.
getvalue
()
target
.
write
(
self
.
stream
.
getvalue
())
if
stream_content
:
target
.
write
(
stream_content
)
def
write
(
self
,
what
):
if
not
self
.
stream
:
self
.
stream
=
StringIO
()
self
.
stream
.
write
(
what
)
def
commit
(
self
):
def
commit
(
self
):
# Save what we have written until now so that the buffer
# Save what we have written until now so that the buffer
# itself is empty -- this makes it ready for insertion
# itself is empty -- this makes it ready for insertion
if
self
.
stream
:
if
self
.
stream
.
tell
()
:
self
.
prepended_children
.
append
(
StringIOTree
(
self
.
stream
))
self
.
prepended_children
.
append
(
StringIOTree
(
self
.
stream
))
self
.
stream
=
None
self
.
stream
=
StringIO
()
self
.
write
=
self
.
stream
.
write
def
insert
(
self
,
iotree
):
def
insert
(
self
,
iotree
):
"""
"""
...
@@ -87,4 +88,4 @@ EXAMPLE:
...
@@ -87,4 +88,4 @@ EXAMPLE:
>>> a.copyto(out)
>>> a.copyto(out)
>>> out.getvalue().split()
>>> out.getvalue().split()
['first', 'second', 'alpha', 'inserted', 'beta', 'gamma', 'third']
['first', 'second', 'alpha', 'inserted', 'beta', 'gamma', 'third']
"""
"""
\ No newline at end of file
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