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
e159ce51
Commit
e159ce51
authored
Jan 17, 2008
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Further optimizations on tp_clear/traverse
parent
6d16147e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
17 deletions
+30
-17
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+30
-17
No files found.
Cython/Compiler/ModuleNode.py
View file @
e159ce51
...
@@ -712,26 +712,34 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -712,26 +712,34 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
"}"
)
"}"
)
def
generate_traverse_function
(
self
,
scope
,
code
):
def
generate_traverse_function
(
self
,
scope
,
code
):
tp_slot
=
TypeSlots
.
GCDependentSlot
(
"tp_traverse"
)
slot_func
=
scope
.
mangle_internal
(
"tp_traverse"
)
base_type
=
scope
.
parent_type
.
base_type
base_type
=
scope
.
parent_type
.
base_type
if
tp_slot
.
slot_code
(
scope
)
!=
slot_func
:
return
# never used
code
.
putln
(
""
)
code
.
putln
(
""
)
code
.
putln
(
code
.
putln
(
"static int %s(PyObject *o, visitproc v, void *a) {"
"static int %s(PyObject *o, visitproc v, void *a) {"
%
s
cope
.
mangle_internal
(
"tp_traverse"
)
)
%
s
lot_func
)
py_attrs
=
[]
py_attrs
=
[]
for
entry
in
scope
.
var_entries
:
for
entry
in
scope
.
var_entries
:
if
entry
.
type
.
is_pyobject
and
entry
.
name
!=
"__weakref__"
:
if
entry
.
type
.
is_pyobject
and
entry
.
name
!=
"__weakref__"
:
py_attrs
.
append
(
entry
)
py_attrs
.
append
(
entry
)
if
base_type
or
py_attrs
:
if
base_type
or
py_attrs
:
code
.
putln
(
code
.
putln
(
"int e;"
)
"int e;"
)
if
py_attrs
:
if
py_attrs
:
self
.
generate_self_cast
(
scope
,
code
)
self
.
generate_self_cast
(
scope
,
code
)
if
base_type
:
if
base_type
:
code
.
putln
(
"if (%s->tp_traverse) {"
%
base_type
.
typeptr_cname
)
# want to call it explicitly if possible so inlining can be performed
code
.
putln
(
parent_slot
=
tp_slot
.
slot_code
(
base_type
.
scope
)
"e = %s->tp_traverse(o, v, a); if (e) return e;"
%
if
scope
.
parent_scope
is
base_type
.
scope
.
parent_scope
and
parent_slot
!=
'0'
:
base_type
.
typeptr_cname
)
code
.
putln
(
"e = %s(o, v, a); if (e) return e;"
%
parent_slot
)
code
.
putln
(
"}"
)
else
:
code
.
putln
(
"if (%s->tp_traverse) {"
%
base_type
.
typeptr_cname
)
code
.
putln
(
"e = %s->tp_traverse(o, v, a); if (e) return e;"
%
base_type
.
typeptr_cname
)
code
.
putln
(
"}"
)
for
entry
in
py_attrs
:
for
entry
in
py_attrs
:
var_code
=
"p->%s"
%
entry
.
cname
var_code
=
"p->%s"
%
entry
.
cname
code
.
putln
(
code
.
putln
(
...
@@ -750,11 +758,13 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -750,11 +758,13 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
"}"
)
"}"
)
def
generate_clear_function
(
self
,
scope
,
code
):
def
generate_clear_function
(
self
,
scope
,
code
):
tp_slot
=
TypeSlots
.
GCDependentSlot
(
"tp_clear"
)
slot_func
=
scope
.
mangle_internal
(
"tp_clear"
)
base_type
=
scope
.
parent_type
.
base_type
base_type
=
scope
.
parent_type
.
base_type
if
tp_slot
.
slot_code
(
scope
)
!=
slot_func
:
return
# never used
code
.
putln
(
""
)
code
.
putln
(
""
)
code
.
putln
(
code
.
putln
(
"static int %s(PyObject *o) {"
%
slot_func
)
"static int %s(PyObject *o) {"
%
scope
.
mangle_internal
(
"tp_clear"
))
py_attrs
=
[]
py_attrs
=
[]
for
entry
in
scope
.
var_entries
:
for
entry
in
scope
.
var_entries
:
if
entry
.
type
.
is_pyobject
and
entry
.
name
!=
"__weakref__"
:
if
entry
.
type
.
is_pyobject
and
entry
.
name
!=
"__weakref__"
:
...
@@ -763,11 +773,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -763,11 +773,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self
.
generate_self_cast
(
scope
,
code
)
self
.
generate_self_cast
(
scope
,
code
)
code
.
putln
(
"PyObject* tmp;"
)
code
.
putln
(
"PyObject* tmp;"
)
if
base_type
:
if
base_type
:
code
.
putln
(
"if (%s->tp_clear) {"
%
base_type
.
typeptr_cname
)
# want to call it explicitly if possible so inlining can be performed
code
.
putln
(
parent_slot
=
tp_slot
.
slot_code
(
base_type
.
scope
)
"%s->tp_clear(o);"
%
if
scope
.
parent_scope
is
base_type
.
scope
.
parent_scope
and
parent_slot
!=
'0'
:
base_type
.
typeptr_cname
)
code
.
putln
(
"%s(o);"
%
parent_slot
)
code
.
putln
(
"}"
)
else
:
code
.
putln
(
"if (%s->tp_clear) {"
%
base_type
.
typeptr_cname
)
code
.
putln
(
"%s->tp_clear(o);"
%
base_type
.
typeptr_cname
)
code
.
putln
(
"}"
)
for
entry
in
py_attrs
:
for
entry
in
py_attrs
:
name
=
"p->%s"
%
entry
.
cname
name
=
"p->%s"
%
entry
.
cname
code
.
putln
(
"tmp = %s;"
%
name
)
code
.
putln
(
"tmp = %s;"
%
name
)
...
@@ -777,7 +790,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
...
@@ -777,7 +790,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
"return 0;"
)
"return 0;"
)
code
.
putln
(
code
.
putln
(
"}"
)
"}"
)
def
generate_getitem_int_function
(
self
,
scope
,
code
):
def
generate_getitem_int_function
(
self
,
scope
,
code
):
# This function is put into the sq_item slot when
# This function is put into the sq_item slot when
# a __getitem__ method is present. It converts its
# a __getitem__ method is present. It converts its
...
...
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