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
f9b8f893
Commit
f9b8f893
authored
Nov 12, 2008
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed bug in Visitor cache, reduces lxml compile time by ~20%
parent
cac97e27
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
12 deletions
+19
-12
Cython/Compiler/Visitor.py
Cython/Compiler/Visitor.py
+19
-12
No files found.
Cython/Compiler/Visitor.py
View file @
f9b8f893
...
@@ -16,24 +16,31 @@ class BasicVisitor(object):
...
@@ -16,24 +16,31 @@ class BasicVisitor(object):
self
.
dispatch_table
=
{}
self
.
dispatch_table
=
{}
def
visit
(
self
,
obj
):
def
visit
(
self
,
obj
):
cls
=
obj
.
__class__
cls
=
type
(
obj
)
m
=
self
.
dispatch_table
.
get
(
cls
.
__name__
)
try
:
if
m
is
None
:
handler_method
=
self
.
dispatch_table
[
cls
]
except
KeyError
:
#print "Cache miss for class %s in visitor %s" % (
# cls.__name__, type(self).__name__)
# Must resolve, try entire hierarchy
# Must resolve, try entire hierarchy
pattern
=
"visit_%s"
pattern
=
"visit_%s"
mro
=
inspect
.
getmro
(
cls
)
mro
=
inspect
.
getmro
(
cls
)
for
cls
in
mro
:
for
mro_
cls
in
mro
:
m
=
getattr
(
self
,
pattern
%
cls
.
__name__
,
None
)
try
:
if
m
is
not
None
:
handler_method
=
getattr
(
self
,
pattern
%
mro_cls
.
__name__
)
break
break
except
AttributeError
:
pass
else
:
else
:
print
type
(
self
),
type
(
obj
)
print
type
(
self
),
type
(
obj
)
if
hasattr
(
self
,
'access_path'
):
print
self
.
access_path
print
self
.
access_path
print
self
.
access_path
[
-
1
][
0
].
pos
print
self
.
access_path
[
-
1
][
0
].
pos
print
self
.
access_path
[
-
1
][
0
].
__dict__
print
self
.
access_path
[
-
1
][
0
].
__dict__
raise
RuntimeError
(
"Visitor does not accept object: %s"
%
obj
)
raise
RuntimeError
(
"Visitor does not accept object: %s"
%
obj
)
self
.
dispatch_table
[
cls
.
__name__
]
=
m
#print "Caching " + cls.__name__
return
m
(
obj
)
self
.
dispatch_table
[
cls
]
=
handler_method
return
handler_method
(
obj
)
class
TreeVisitor
(
BasicVisitor
):
class
TreeVisitor
(
BasicVisitor
):
"""
"""
...
...
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