Eric Snow
96c6af9b20
Issue #16991 : Add a C implementation of collections.OrderedDict.
11 years ago
Eric Snow
47db71756d
Issue #16991 : Add a C implementation of collections.OrderedDict.
11 years ago
Raymond Hettinger
c6249a6268
Defer deleted item decref until after the deque is restored to a consistent state.
11 years ago
Benjamin Peterson
1a6292194b
fix refleak in deque_concat
11 years ago
Raymond Hettinger
41290a68ba
Issue 23793: Add deque support for __add__(), __mul__(), and __imul__().
11 years ago
Raymond Hettinger
fef9c1b368
Fix typo
11 years ago
Raymond Hettinger
8dbbae2e52
Minor code and comment cleanups.
11 years ago
Raymond Hettinger
551350a79f
Improve and fix-up comments.
11 years ago
Raymond Hettinger
0f1451c8c0
Issue 23744: Minor speed-up for deque.__bool__().
11 years ago
Raymond Hettinger
6921c13bbb
Minor nit. Make the rotate() success/fail tests consistent.
11 years ago
Raymond Hettinger
ac13ad6a32
For safety, wait to decref deleted values until the deque state has been restored.
11 years ago
Raymond Hettinger
0f6f94778a
Fix minor formatting nits and remove unnecessary comment.
11 years ago
Raymond Hettinger
32ea16577d
Issue 23704: Add index(), copy(), and insert() to deques. Register deques as a MutableSequence.
11 years ago
Raymond Hettinger
39dadf7abf
Issue 23705: Improve the performance of __contains__ checks for deques.
11 years ago
Raymond Hettinger
87e691240b
Minor neatening-up. Make assignments in same order a struct fields. Line-up comments.
11 years ago
Raymond Hettinger
f9d9c79aa8
Switch the state variable to unsigned for defined wrap-around behavior.
11 years ago
Raymond Hettinger
30c9074b96
Minor beautification. Move struct definitions to the top. Fix-up a comment.
11 years ago
Raymond Hettinger
f30f5b9ba6
Minor code beautification. Replace macro with in-lineable functions.
11 years ago
Raymond Hettinger
3c186ba441
Beautify and better document the use of the size_t cast for bounds checking.
11 years ago
Raymond Hettinger
7f9ea7543e
Issue #23553 : Use an unsigned cast to tighten-up the bounds checking logic.
11 years ago
Raymond Hettinger
c20830804d
Need a (size_t) cast instead of (unsigned) to be big enough for a Py_ssize_t.
11 years ago
Raymond Hettinger
a473b9da15
Use unsigned division and modulo for item assignment as well.
11 years ago
Raymond Hettinger
63d1ff2a0b
Convert one more division to unsigned arithmetic to speed-up deque_item().
11 years ago
Raymond Hettinger
7e8c7956a7
Line missed in last checkin
11 years ago
Raymond Hettinger
da2850f932
Since the index is always non-negative, use faster unsigned division and modulo.
11 years ago
Raymond Hettinger
daf57f25e5
Bump the blocksize up from 62 to 64 to speed up the modulo calculation.
Remove the old comment suggesting that it was desireable to have
blocksize+2 as a multiple of the cache line length. That would
have made sense only if the block structure start point was always
aligned to a cache line boundary. However, the memory allocations
are 16 byte aligned, so we don't really have control over whether
the struct spills across cache line boundaries.
11 years ago
Raymond Hettinger
eb6b554fbc
Update copyright.
11 years ago
Raymond Hettinger
0e259f18f7
Optimization guides suggest copying memory in an ascending direction when possible.
11 years ago
Raymond Hettinger
507d997714
Add comment and make minor code clean-up to improve clarity.
12 years ago
Raymond Hettinger
4b0b1accb5
Issue #21101 : Eliminate double hashing in the C code for collections.Counter().
12 years ago
Raymond Hettinger
5402315626
Add implementation notes
12 years ago
Benjamin Peterson
9cb33b7d03
correct defaultdict signature in docstring ( closes #20250 )
Patch from Andrew Barnert.
12 years ago
Victor Stinner
e7f516cbb8
Issue #19512 : _count_elements() of _collections reuses PyId_get identifier
instead of literal "get" string
13 years ago
Raymond Hettinger
cb1d96f782
Issue #18594 : Make the C code more closely match the pure python code.
13 years ago
Raymond Hettinger
224c87d60c
Issue #18594 : Fix the fallback path in collections.Counter().
13 years ago
Raymond Hettinger
2ff2190b62
Issue #18594 : Fix the fast path for collections.Counter().
The path wasn't being taken due to an over-restrictive type check.
13 years ago
Raymond Hettinger
77578204d6
Restore the data block size to 62.
The former block size traded away good fit within cache lines in
order to gain faster division in deque_item(). However, compilers
are getting smarter and can now replace the slow division operation
with a fast integer multiply and right shift. Accordingly, it makes
sense to go back to a size that lets blocks neatly fill entire
cache-lines.
GCC-4.8 and CLANG 4.0 both compute "x // 62" with something
roughly equivalent to "x * 9520900167075897609 >> 69".
13 years ago
Raymond Hettinger
3223dd5c22
Assertions key off NDEBUG
13 years ago
Raymond Hettinger
b97cc49c3a
Minor code simplification by eliminating an unnecessary temporary variable.
13 years ago
Raymond Hettinger
90dea4ce43
Tweak the deque struct by moving the least used fields (maxlen and weakref) to the end.
13 years ago
Raymond Hettinger
840533bf1c
Use a do-while loop in the inner loop for rotate (m is always greater than zero).
13 years ago
Raymond Hettinger
3959af9b2a
Move the freeblock() call outside the main loop to speed-up and simplify the block re-use logic.
13 years ago
Raymond Hettinger
d9c116ca40
Add a spacing saving heuristic to deque's extend methods
13 years ago
Raymond Hettinger
b385529ddf
Fix #ifdef
13 years ago
Raymond Hettinger
82df925451
Use macros for marking and checking endpoints in the doubly-linked list of blocks.
* Add comment explaining the endpoint checks
* Only do the checks in a debug build
* Simplify newblock() to only require a length argument
and leave the link updates to the calling code.
* Also add comment for the freelisting logic.
13 years ago
Raymond Hettinger
f3a67b7e57
Improve variable names in deque_count()
13 years ago
Raymond Hettinger
df715ba54d
Apply the PyObject_VAR_HEAD and Py_SIZE macros
to be consistent with practices in other modules.
13 years ago
Raymond Hettinger
5bfa8671bc
Refactor deque_traverse().
Hoist conditional expression out of the loop.
Use rightblock as the guard instead of checking for NULL.
13 years ago
Raymond Hettinger
98054b4c1b
Remove unnecessary branches from count() and reverse().
13 years ago
Raymond Hettinger
de68e0cf0e
Speed-up deque indexing by changing the deque block length to a power of two.
The division and modulo calculation in deque_item() can be compiled
to fast bitwise operations when the BLOCKLEN is a power of two.
Timing before:
~/cpython $ py -m timeit -r7 -s 'from collections import deque' -s 'd=deque(range(10))' 'd[5]'
10000000 loops, best of 7: 0.0627 usec per loop
Timing after:
~/cpython $ py -m timeit -r7 -s 'from collections import deque' -s 'd=deque(range(10))' 'd[5]'
10000000 loops, best of 7: 0.0581 usec per loop
13 years ago