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
Boxiang Sun
cython
Commits
fdac73d6
Commit
fdac73d6
authored
9 years ago
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add alternative pylong_join() implementation (slower than what's there), purely for documentation
parent
de9d987e
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
0 deletions
+16
-0
Cython/Utility/__init__.py
Cython/Utility/__init__.py
+16
-0
No files found.
Cython/Utility/__init__.py
View file @
fdac73d6
...
...
@@ -7,3 +7,19 @@ def pylong_join(count, digits_ptr='digits', join_type='unsigned long'):
return
(
'('
*
(
count
*
2
)
+
"(%s)"
%
join_type
+
' | '
.
join
(
"%s[%d])%s)"
%
(
digits_ptr
,
_i
,
" << PyLong_SHIFT"
if
_i
else
''
)
for
_i
in
range
(
count
-
1
,
-
1
,
-
1
)))
# although it could potentially make use of data independence,
# this implementation is a bit slower than the simpler one above
def
_pylong_join
(
count
,
digits_ptr
=
'digits'
,
join_type
=
'unsigned long'
):
"""
Generate an unrolled shift-then-or loop over the first 'count' digits.
Assumes that they fit into 'join_type'.
"""
def
shift
(
n
):
# avoid compiler warnings for overly large shifts that will be discarded anyway
return
" << (%d * PyLong_SHIFT < 8 * sizeof(%s) ? %d * PyLong_SHIFT : 0)"
%
(
n
,
join_type
,
n
)
if
n
else
''
return
'(%s)'
%
' | '
.
join
(
"(((%s)%s[%d])%s)"
%
(
join_type
,
digits_ptr
,
i
,
shift
(
i
))
for
i
in
range
(
count
-
1
,
-
1
,
-
1
))
This diff is collapsed.
Click to expand it.
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