Commit Graph

199 Commits

Author SHA1 Message Date
Raymond Hettinger
1202a4733e Issue 23261: Clean-up the hack to store the set.pop() search finger in a hash field instead of the setobject. 2015-01-18 13:12:42 -08:00
Raymond Hettinger
8edf27c134 Small clean-up. Factor-out common code for add, contains, and discard function pairs. 2014-12-26 23:08:58 -08:00
Raymond Hettinger
08e3dc0ad6 Issue #23107: Tighten-up loops in setobject.c
* Move the test for an exact key match to after a hash match
* Use "used" as a loop counter instead of "fill"
* Minor improvements to variable names and code consistency
2014-12-26 20:14:00 -08:00
Victor Stinner
12174a5dca Issue #22156: Fix "comparison between signed and unsigned integers" compiler
warnings in the Objects/ subdirectory.

PyType_FromSpecWithBases() and PyType_FromSpec() now reject explicitly negative
slot identifiers.
2014-08-15 23:17:38 +02:00
Raymond Hettinger
426d9958a2 Add development comments to setobject.c 2014-05-18 21:40:20 +01:00
Eric V. Smith
6ba5665fc7 Fix typo in comment. 2014-01-14 08:15:03 -05:00
Raymond Hettinger
74fc8c47f6 Add comments to frozenset_hash().
Also, provide a minor hint to the compiler on how to group the xors.
2014-01-05 12:00:31 -08:00
Raymond Hettinger
e259f13874 Minor code clean-up. Keep the C-API all in one section. 2013-12-15 11:56:14 -08:00
Raymond Hettinger
710a67edfc Note that LINEAR_PROBES can be set to zero. 2013-09-21 20:17:31 -07:00
Raymond Hettinger
4ef0528b97 Minor beautification. Put updates and declarations in a more logical order. 2013-09-21 15:39:49 -07:00
Raymond Hettinger
0ce1953bf7 When LINEAR_PROBES=0, let the compiler remove the dead code on its own. 2013-09-21 14:07:18 -07:00
Raymond Hettinger
c70a2b7bb9 Make the linear probe sequence clearer. 2013-09-21 14:02:55 -07:00
Raymond Hettinger
8408dc581e Issue 18771: Make it possible to set the number linear probes at compile-time. 2013-09-15 14:57:15 -07:00
Raymond Hettinger
742d8716ff Put the defines in the logical section and fix indentation. 2013-09-08 00:25:57 -07:00
Raymond Hettinger
583cd03fd1 Minor code beautification. 2013-09-07 22:06:35 -07:00
Raymond Hettinger
4ea9080da9 Improve code clarity by removing two unattractive macros. 2013-09-07 21:01:29 -07:00
Raymond Hettinger
8f8839e10a Remove the freelist scheme for setobjects.
The setobject freelist was consuming memory but not providing much value.
Even when a freelisted setobject was available, most of the setobject
fields still needed to be initialized and the small table still required
a memset().  This meant that the custom freelisting scheme for sets was
providing almost no incremental benefit over the default Python freelist
scheme used by _PyObject_Malloc() in Objects/obmalloc.c.
2013-09-07 20:26:50 -07:00
Raymond Hettinger
04fd9dd52b Small rearrangement to bring together the three functions for probing the hash table. 2013-09-07 17:41:01 -07:00
Raymond Hettinger
ae7b00e2d3 Move the overview comment to the top of the file. 2013-09-07 15:05:00 -07:00
Raymond Hettinger
c56e0e3980 Minor touchups. 2013-09-02 16:32:27 -07:00
Raymond Hettinger
69492dab07 Factor-out the common code for setting a KeyError. 2013-09-02 15:59:26 -07:00
Raymond Hettinger
a35adf5b09 Instead of XORed indicies, switch to a hybrid of linear probing and open addressing.
Modern processors tend to make consecutive memory accesses cheaper than
random probes into memory.

Small sets can fit into L1 cache, so they get less benefit.  But they do
come out ahead because the consecutive probes don't probe the same key
more than once and because the randomization step occurs less frequently
(or not at all).

For the open addressing step, putting the perturb shift before the index
calculation gets the upper bits into play sooner.
2013-09-02 03:23:21 -07:00
Raymond Hettinger
6c3c1ccd1b Update copyright. 2013-08-31 21:34:24 -07:00
Raymond Hettinger
95c0d67581 Further reduce the cost of hash collisions by inspecting an additional nearby entry. 2013-08-31 21:27:08 -07:00
Raymond Hettinger
afe890923f Tighten-up the lookkey() logic and beautify the code a bit.
Use less code by moving many of the steps from the initial
lookup into the main search loop.

Beautify the code but keep the overall logic unchanged.
2013-08-28 20:59:31 -07:00
Antoine Pitrou
9d95254bb7 Issue #18772: fix the gdb plugin after the set implementation changes 2013-08-24 21:07:07 +02:00
Raymond Hettinger
bfc1e1a9cd Add the same dummy type that is used in dictionaries. 2013-08-23 03:22:15 -05:00
Raymond Hettinger
fcf3b500ba Issue 18797: Remove unneeded refcount adjustments for dummy objects.
It suffices to keep just one reference when the object is created.
2013-08-22 08:20:31 -07:00
Raymond Hettinger
5bb1b1dd6f Hoist the global dummy lookup out of the inner loop for set_merge(). 2013-08-21 01:34:18 -07:00
Raymond Hettinger
929cbac307 Remove a redundant hash table probe (this was artifact from an earlier draft of the patch). 2013-08-20 23:03:28 -07:00
Raymond Hettinger
ae9e616a00 Issue 18772: Restore set dummy object back to unicode and restore the identity checks in lookkey().
The Gdb prettyprint plugin depended on the dummy object being displayable.
Other solutions besides a unicode object are possible.  For now, get it
back up and running.

The identity checks in lookkey() need to be there to prevent the dummy
object from leaking through Py_RichCompareBool() into user code in the
rare circumstance where the dummy's hash value exactly matches the hash
value of the actual key being looked up.
2013-08-20 22:28:24 -07:00
Raymond Hettinger
3c0a4f5def Issue18771: Reduce the cost of hash collisions for set objects. 2013-08-19 07:36:04 -07:00
Raymond Hettinger
07351a0449 Remove the else-clause because the conditions are no longer mutually exclusive. 2013-08-17 02:39:46 -07:00
Raymond Hettinger
237b34b074 Use a known unique object for the dummy entry.
This lets us run PyObject_RichCompareBool() without
first needing to check whether the entry is a dummy.
2013-08-17 02:31:53 -07:00
Raymond Hettinger
8ad3919577 Hoist the global "dummy" lookup outside of the reinsertion loop. 2013-08-15 02:18:55 -07:00
Antoine Pitrou
9ed5f27266 Issue #18722: Remove uses of the "register" keyword in C code. 2013-08-13 20:18:52 +02:00
Raymond Hettinger
c629d4c9a2 Replace outdated optimization with clearer code that compiles better.
Letting the compiler decide how to optimize the multiply by five
gives it the freedom to make better choices for the best technique
for a given target machine.

For example, GCC on x86_64 produces a little bit better code:

Old-way (3 steps with a data dependency between each step):

    shrq    $5, %r13
    leaq    1(%rbx,%r13), %rax
    leaq    (%rax,%rbx,4), %rbx

New-way (3 steps with no dependency between the first two steps
         which can be run in parallel):

    leaq    (%rbx,%rbx,4), %rax     # i*5
    shrq    $5, %r13                # perturb >>= PERTURB_SHIFT
    leaq    1(%r13,%rax), %rbx      # 1 + perturb + i*5
2013-08-05 22:24:50 -07:00
Antoine Pitrou
5e946bacef Fix compilation warning with gcc 4.8 (unused typedef) 2013-06-18 23:28:18 +02:00
Gregory P. Smith
c2176e46d7 Fix the internals of our hash functions to used unsigned values during hash
computation as the overflow behavior of signed integers is undefined.

NOTE: This change is smaller compared to 3.2 as much of this cleanup had
already been done.  I added the comment that my change in 3.2 added so that the
code would match up.  Otherwise this just adds or synchronizes appropriate UL
designations on some constants to be pedantic.

In practice we require compiling everything with -fwrapv which forces overflow
to be defined as twos compliment but this keeps the code cleaner for checkers
or in the case where someone has compiled it without -fwrapv or their
compiler's equivalent.

Found by Clang trunk's Undefined Behavior Sanitizer (UBSan).

Cleanup only - no functionality or hash values change.
2012-12-10 18:32:53 -08:00
Gregory P. Smith
27cbcd6241 Fix the internals of our hash functions to used unsigned values during hash
computation as the overflow behavior of signed integers is undefined.

In practice we require compiling everything with -fwrapv which forces overflow
to be defined as twos compliment but this keeps the code cleaner for checkers
or in the case where someone has compiled it without -fwrapv or their
compiler's equivalent.

Found by Clang trunk's Undefined Behavior Sanitizer (UBSan).

Cleanup only - no functionality or hash values change.
2012-12-10 18:15:46 -08:00
Ezio Melotti
0e1af282b8 Fix typo. 2012-09-28 16:43:40 +03:00
David Malcolm
49526f48fc Issue #14785: Add sys._debugmallocstats() to help debug low-level memory allocation issues 2012-06-22 14:55:41 -04:00
Antoine Pitrou
a701388de1 Rename _PyIter_GetBuiltin to _PyObject_GetBuiltin, and do not include it in the stable ABI. 2012-04-05 00:04:20 +02:00
Kristján Valur Jónsson
31668b8f7a Issue #14288: Serialization support for builtin iterators. 2012-04-03 10:49:41 +00:00
Antoine Pitrou
093ce9cd8c Issue #6695: Full garbage collection runs now clear the freelist of set objects.
Initial patch by Matthias Troffaes.
2011-12-16 11:24:27 +01:00
Benjamin Peterson
1cebc207ea merge 3.2 2011-10-30 14:24:59 -04:00
Benjamin Peterson
2b50a01d11 remove unused variable 2011-10-30 14:24:44 -04:00
Petri Lehtinen
c34f5c256a Fix the return value of set_discard (issue #10519) 2011-10-30 14:35:39 +02:00
Petri Lehtinen
e0aa803714 Fix the return value of set_discard (issue #10519) 2011-10-30 14:35:12 +02:00
Petri Lehtinen
7c5e34d8a3 Avoid unnecessary recursive function calls (#closes #10519) 2011-10-30 13:57:45 +02:00