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
45da07ea
Commit
45da07ea
authored
Feb 26, 2009
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize printing of one object.
parent
eaae26b8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
8 deletions
+48
-8
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+48
-8
No files found.
Cython/Compiler/Nodes.py
View file @
45da07ea
...
...
@@ -3200,14 +3200,24 @@ class PrintStatNode(StatNode):
gil_message
=
"Python print statement"
def
generate_execution_code
(
self
,
code
):
self
.
arg_tuple
.
generate_evaluation_code
(
code
)
code
.
putln
(
"if (__Pyx_Print(%s, %d) < 0) %s"
%
(
self
.
arg_tuple
.
py_result
(),
self
.
append_newline
,
code
.
error_goto
(
self
.
pos
)))
self
.
arg_tuple
.
generate_disposal_code
(
code
)
self
.
arg_tuple
.
free_temps
(
code
)
if
len
(
self
.
arg_tuple
.
args
)
==
1
and
self
.
append_newline
:
arg
=
self
.
arg_tuple
.
args
[
0
]
arg
.
generate_evaluation_code
(
code
)
code
.
putln
(
"if (__Pyx_PrintOne(%s) < 0) %s"
%
(
arg
.
py_result
(),
code
.
error_goto
(
self
.
pos
)))
arg
.
generate_disposal_code
(
code
)
arg
.
free_temps
(
code
)
else
:
self
.
arg_tuple
.
generate_evaluation_code
(
code
)
code
.
putln
(
"if (__Pyx_Print(%s, %d) < 0) %s"
%
(
self
.
arg_tuple
.
py_result
(),
self
.
append_newline
,
code
.
error_goto
(
self
.
pos
)))
self
.
arg_tuple
.
generate_disposal_code
(
code
)
self
.
arg_tuple
.
free_temps
(
code
)
def
annotate
(
self
,
code
):
self
.
arg_tuple
.
annotate
(
code
)
...
...
@@ -4746,6 +4756,7 @@ else:
printing_utility_code
=
UtilityCode
(
proto
=
"""
static int __Pyx_Print(PyObject *, int); /*proto*/
static int __Pyx_PrintOne(PyObject *o); /*proto*/
#if PY_MAJOR_VERSION >= 3
static PyObject* %s = 0;
static PyObject* %s = 0;
...
...
@@ -4793,7 +4804,23 @@ static int __Pyx_Print(PyObject *arg_tuple, int newline) {
return 0;
}
static int __Pyx_PrintOne(PyObject *o) {
PyObject *f;
if (!(f = __Pyx_GetStdout()))
return -1;
if (PyFile_SoftSpace(f, 0)) {
if (PyFile_WriteString(" ", f) < 0)
return -1;
}
if (PyFile_WriteObject(o, f, Py_PRINT_RAW) < 0)
return -1;
if (PyFile_WriteString("\n", f) < 0)
return -1;
return 0;
}
#else /* Python 3 has a print function */
static int __Pyx_Print(PyObject *arg_tuple, int newline) {
PyObject* kwargs = 0;
PyObject* result = 0;
...
...
@@ -4825,6 +4852,19 @@ static int __Pyx_Print(PyObject *arg_tuple, int newline) {
Py_DECREF(result);
return 0;
}
static int __Pyx_PrintOne(PyObject *o) {
int res;
PyObject* arg_tuple = PyTuple_New(1);
if (unlikely(!arg_tuple))
return -1;
Py_INCREF(o);
PyTuple_SET_ITEM(arg_tuple, 0, o);
res = __Pyx_Print(arg_tuple, 1);
Py_DECREF(arg_tuple);
return res;
}
#endif
"""
%
{
'BUILTINS'
:
Naming
.
builtins_cname
,
'PRINT_FUNCTION'
:
Naming
.
print_function
,
...
...
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