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
b6d2b2fc
Commit
b6d2b2fc
authored
Jul 06, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avoid repeated substring replacing for PYIDENT() entries in utility code
parent
cc786153
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
8 deletions
+12
-8
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+12
-8
No files found.
Cython/Compiler/Code.py
View file @
b6d2b2fc
...
...
@@ -384,14 +384,18 @@ class UtilityCode(UtilityCodeBase):
def
inject_string_constants
(
self
,
impl
,
output
):
"""Replace 'PYIDENT("xyz")' by a constant Python identifier cname.
"""
pystrings
=
re
.
findall
(
'(PYIDENT
\
(
"
([^"]+)"
\
))
'
, impl)
any_replacements = False
for ref, name in pystrings:
py_const = output.get_interned_identifier(
StringEncoding.EncodedString(name))
any_replacements = True
impl = impl.replace(ref, py_const.cname)
return any_replacements, impl
replacements
=
{}
def
externalise
(
matchobj
):
name
=
matchobj
.
group
(
1
)
try
:
cname
=
replacements
[
name
]
except
KeyError
:
cname
=
replacements
[
name
]
=
output
.
get_interned_identifier
(
StringEncoding
.
EncodedString
(
name
)).
cname
return
cname
impl
=
re
.
sub
(
'PYIDENT
\
(
"
([^"]+)"
\
)
'
, externalise, impl)
return bool(replacements), impl
def put_code(self, output):
if self.requires:
...
...
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