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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
c9db2725
Commit
c9db2725
authored
Dec 04, 2008
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid some trivial tree traversal to speed up compilation.
parent
5ede4238
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
6 deletions
+58
-6
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+3
-1
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+55
-5
No files found.
Cython/Compiler/Optimize.py
View file @
c9db2725
...
@@ -8,6 +8,8 @@ import TypeSlots
...
@@ -8,6 +8,8 @@ import TypeSlots
import
Symtab
import
Symtab
from
StringEncoding
import
EncodedString
from
StringEncoding
import
EncodedString
from
ParseTreeTransforms
import
SkipDeclarations
#def unwrap_node(node):
#def unwrap_node(node):
# while isinstance(node, ExprNodes.PersistentNode):
# while isinstance(node, ExprNodes.PersistentNode):
# node = node.arg
# node = node.arg
...
@@ -292,7 +294,7 @@ class SwitchTransform(Visitor.VisitorTransform):
...
@@ -292,7 +294,7 @@ class SwitchTransform(Visitor.VisitorTransform):
return
node
return
node
class
FlattenInListTransform
(
Visitor
.
VisitorTransform
):
class
FlattenInListTransform
(
Visitor
.
VisitorTransform
,
SkipDeclarations
):
"""
"""
This transformation flattens "x in [val1, ..., valn]" into a sequential list
This transformation flattens "x in [val1, ..., valn]" into a sequential list
of comparisons.
of comparisons.
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
c9db2725
...
@@ -12,6 +12,33 @@ except NameError:
...
@@ -12,6 +12,33 @@ except NameError:
from
sets
import
Set
as
set
from
sets
import
Set
as
set
import
copy
import
copy
class
SkipDeclarations
:
"""
Variable and function declarations can often have a deep tree structure,
and yet most transformations don't need to descend to this depth.
Declaration nodes are removed after AnalyseDeclarationsTransform, so there
is no need to use this for transformations after that point.
"""
def
visit_CTypeDefNode
(
self
,
node
):
return
node
def
visit_CVarDefNode
(
self
,
node
):
return
node
def
visit_CDeclaratorNode
(
self
,
node
):
return
node
def
visit_CBaseTypeNode
(
self
,
node
):
return
node
def
visit_CEnumDefNode
(
self
,
node
):
return
node
def
visit_CStructOrUnionDefNode
(
self
,
node
):
return
node
class
NormalizeTree
(
CythonTransform
):
class
NormalizeTree
(
CythonTransform
):
"""
"""
This transform fixes up a few things after parsing
This transform fixes up a few things after parsing
...
@@ -77,6 +104,9 @@ class NormalizeTree(CythonTransform):
...
@@ -77,6 +104,9 @@ class NormalizeTree(CythonTransform):
else
:
else
:
return
[]
return
[]
def
visit_CDeclaratorNode
(
self
,
node
):
return
node
class
PostParseError
(
CompileError
):
pass
class
PostParseError
(
CompileError
):
pass
...
@@ -202,7 +232,7 @@ class PostParse(CythonTransform):
...
@@ -202,7 +232,7 @@ class PostParse(CythonTransform):
raise
PostParseError
(
node
.
pos
,
ERR_BUF_LOCALONLY
)
raise
PostParseError
(
node
.
pos
,
ERR_BUF_LOCALONLY
)
return
node
return
node
class
PxdPostParse
(
CythonTransform
):
class
PxdPostParse
(
CythonTransform
,
SkipDeclarations
):
"""
"""
Basic interpretation/validity checking that should only be
Basic interpretation/validity checking that should only be
done on pxd trees.
done on pxd trees.
...
@@ -268,7 +298,7 @@ class PxdPostParse(CythonTransform):
...
@@ -268,7 +298,7 @@ class PxdPostParse(CythonTransform):
else
:
else
:
return
node
return
node
class
InterpretCompilerDirectives
(
CythonTransform
):
class
InterpretCompilerDirectives
(
CythonTransform
,
SkipDeclarations
):
"""
"""
After parsing, options can be stored in a number of places:
After parsing, options can be stored in a number of places:
- #cython-comments at the top of the file (stored in ModuleNode)
- #cython-comments at the top of the file (stored in ModuleNode)
...
@@ -457,7 +487,7 @@ class InterpretCompilerDirectives(CythonTransform):
...
@@ -457,7 +487,7 @@ class InterpretCompilerDirectives(CythonTransform):
else
:
else
:
return
self
.
visit_Node
(
node
)
return
self
.
visit_Node
(
node
)
class
WithTransform
(
CythonTransform
):
class
WithTransform
(
CythonTransform
,
SkipDeclarations
):
# EXCINFO is manually set to a variable that contains
# EXCINFO is manually set to a variable that contains
# the exc_info() tuple that can be generated by the enclosing except
# the exc_info() tuple that can be generated by the enclosing except
...
@@ -525,7 +555,12 @@ class WithTransform(CythonTransform):
...
@@ -525,7 +555,12 @@ class WithTransform(CythonTransform):
return
TempsBlockNode
(
node
.
pos
,
temps
=
[
excinfo_temp
],
body
=
result
)
return
TempsBlockNode
(
node
.
pos
,
temps
=
[
excinfo_temp
],
body
=
result
)
class
DecoratorTransform
(
CythonTransform
):
def
visit_ExprNode
(
self
,
node
):
# With statements are never inside expressions.
return
node
class
DecoratorTransform
(
CythonTransform
,
SkipDeclarations
):
def
visit_DefNode
(
self
,
func_node
):
def
visit_DefNode
(
self
,
func_node
):
if
not
func_node
.
decorators
:
if
not
func_node
.
decorators
:
...
@@ -587,6 +622,21 @@ property NAME:
...
@@ -587,6 +622,21 @@ property NAME:
# analysis and can be dropped. The analysis was performed
# analysis and can be dropped. The analysis was performed
# on these nodes in a seperate recursive process from the
# on these nodes in a seperate recursive process from the
# enclosing function or module, so we can simply drop them.
# enclosing function or module, so we can simply drop them.
def
visit_CDeclaratorNode
(
self
,
node
):
return
node
def
visit_CTypeDefNode
(
self
,
node
):
return
node
def
visit_CBaseTypeNode
(
self
,
node
):
return
None
def
visit_CEnumDefNode
(
self
,
node
):
return
None
def
visit_CStructOrUnionDefNode
(
self
,
node
):
return
None
def
visit_CVarDefNode
(
self
,
node
):
def
visit_CVarDefNode
(
self
,
node
):
if
node
.
need_properties
:
if
node
.
need_properties
:
# cdef public attributes may need type testing on
# cdef public attributes may need type testing on
...
...
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