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
f524e1e8
Commit
f524e1e8
authored
Mar 21, 2016
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reduce code overhead for common f-string formatting case without format specifier
parent
0a631b46
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
30 deletions
+25
-30
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+25
-30
No files found.
Cython/Compiler/ExprNodes.py
View file @
f524e1e8
...
...
@@ -2994,53 +2994,48 @@ class FormattedValueNode(ExprNode):
conversion_chars
=
'sra'
type
=
py_object_type
is_temp
=
True
find_conversion_func
=
{
's'
:
'PyObject_Str'
,
'r'
:
'PyObject_Repr'
,
'a'
:
'PyObject_ASCII'
,
# NOTE: Py3-only!
}.
get
def
analyse_types
(
self
,
env
):
value
=
self
.
value
.
analyse_types
(
env
)
format_spec
=
self
.
format_spec
.
analyse_types
(
env
)
self
.
value
=
value
.
coerce_to_pyobject
(
env
)
self
.
format_spec
=
format_spec
.
coerce_to_pyobject
(
env
)
self
.
is_temp
=
True
self
.
value
=
self
.
value
.
analyse_types
(
env
).
coerce_to_pyobject
(
env
)
self
.
format_spec
=
self
.
format_spec
.
analyse_types
(
env
).
coerce_to_pyobject
(
env
)
return
self
def
generate_result_code
(
self
,
code
):
value_result
=
self
.
value
.
py_result
()
conversion_result
=
Naming
.
quick_temp_cname
format_spec_result
=
self
.
format_spec
.
py_result
()
if
self
.
conversion_char
==
's'
:
fn
=
'PyObject_Str'
elif
self
.
conversion_char
==
'r'
:
fn
=
'PyObject_Repr'
elif
self
.
conversion_char
==
'a'
:
fn
=
'PyObject_ASCII'
else
:
fn
=
None
conversion_result
=
value_result
=
self
.
value
.
py_result
()
code
.
putln
(
'{'
)
if
self
.
conversion_char
:
fn
=
self
.
find_conversion_func
(
self
.
conversion_char
)
if
fn
is
None
:
assert
False
,
"invalid conversion character found: '%s'"
%
self
.
conversion_char
if
fn
is
not
None
:
code
.
putln
(
'{'
)
conversion_result
=
Naming
.
quick_temp_cname
code
.
putln
(
'PyObject *%s = %s(%s); %s'
%
(
conversion_result
,
fn
,
value_result
,
code
.
error_goto_if_null
(
conversion_result
,
self
.
pos
)
))
else
:
code
.
putln
(
'PyObject *%s = %s;'
%
(
conversion_result
,
value_result
))
#code.put_incref(conversion_result, py_object_type)
# TODO this should need more refcounting, figure out whether this is correct
#code.put_gotref(conversion_result)
#code.put_decref(value_result, self.value.ctype())
decref_line
=
''
# '__Pyx_DECREF(%s);' % conversion_result
code
.
put_gotref
(
conversion_result
)
code
.
put
ln
(
"%s = PyObject_Format(%s, %s); %s %s
"
%
(
code
.
put
(
"%s = PyObject_Format(%s, %s);
"
%
(
self
.
result
(),
conversion_result
,
format_spec_result
,
decref_line
,
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
)))
self
.
format_spec
.
py_result
()))
if
self
.
conversion_char
:
code
.
put_decref
(
conversion_result
,
py_object_type
)
code
.
putln
(
'}'
)
code
.
putln
(
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
))
code
.
put_gotref
(
self
.
py_result
())
code
.
putln
(
'}'
)
#-------------------------------------------------------------------
...
...
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