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
f7b8db13
Commit
f7b8db13
authored
Sep 14, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reduce overhead a bit when many string constants have the same cname
parent
9203677c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
7 deletions
+6
-7
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+4
-5
tests/run/strliterals.pyx
tests/run/strliterals.pyx
+2
-2
No files found.
Cython/Compiler/Code.py
View file @
f7b8db13
...
...
@@ -847,7 +847,7 @@ class GlobalState(object):
# In time, hopefully the literals etc. will be
# supplied directly instead.
#
# const_cnames_used
set global index of
unique constant identifiers
# const_cnames_used
dict global counter for
unique constant identifiers
#
# parts {string:CCodeWriter}
...
...
@@ -903,7 +903,7 @@ class GlobalState(object):
self.module_node = module_node # because some utility code generation needs it
# (generating backwards-compatible Get/ReleaseBuffer
self.const_cnames_used =
set()
self.const_cnames_used =
{}
self.string_const_index = {}
self.pyunicode_ptr_const_index = {}
self.int_const_index = {}
...
...
@@ -1108,12 +1108,11 @@ class GlobalState(object):
def
new_const_cname
(
self
,
prefix
=
''
,
value
=
''
):
value
=
replace_identifier
(
'_'
,
value
)[:
32
].
strip
(
'_'
)
used
=
self
.
const_cnames_used
counter
=
1
name_suffix
=
value
while
name_suffix
in
used
:
counter
+=
1
counter
=
used
[
value
]
=
used
[
value
]
+
1
name_suffix
=
'%s_%d'
%
(
value
,
counter
)
used
.
add
(
name_suffix
)
used
[
name_suffix
]
=
1
return
"%s%s%s"
%
(
Naming
.
const_prefix
,
prefix
,
name_suffix
)
def
add_cached_builtin_decl
(
self
,
entry
):
...
...
tests/run/strliterals.pyx
View file @
f7b8db13
...
...
@@ -149,7 +149,7 @@ __doc__ = ur"""
True
>>> same_cname
[b'abc\xf0', b'abc\xf1', b'abc\xf2', b'abc\xf3', b'abc_2', b'abc_3']
[b'abc\xf0
_2', b'abc\xf0
', b'abc\xf1', b'abc\xf2', b'abc\xf3', b'abc_2', b'abc_3']
>>> newlines
'Aaa\n'
...
...
@@ -194,7 +194,7 @@ uresc = ur'\12\'\"\\'
bytes_uescape
=
b'
\
u1234
\
U12345678
\
u
\
u1
\
u
12
\
uX
'
str_uescape = '
\
u0063
\
U00012345
\
N
{
SNOWMAN
}
\
x42
'
same_cname = [b'
abc
\
xf0
', b'
abc
\
xf1
', b'
abc
\
xf2
', b'
abc
\
xf3
', b'
abc_2
', b'
abc_3
']
same_cname = [b'
abc
\
xf0
_2
', b'
abc
\
xf0
', b'
abc
\
xf1
', b'
abc
\
xf2
', b'
abc
\
xf3
', b'
abc_2
', b'
abc_3
']
newlines = "Aaa
\
n
"
...
...
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