Raymond Hettinger
3625af5f21
Moved misplaced functions to the section for C API functions.
2016-03-27 01:15:07 -07:00
Raymond Hettinger
2c257ab0f8
Responsibility for argument checking belongs in set.__init__() rather than set.__new__().
...
See dict.__new__() and list.__new__() for comparison. Neither of those examine or touch
args or kwds. That work is done in the __init__() methods.
2016-03-26 04:10:11 -07:00
Raymond Hettinger
b72e21b9ab
Speed-up construction of empty sets by approx 12-14%.
2016-03-25 02:29:59 -07:00
Raymond Hettinger
f50215412c
Add early-out for the common case where kwds is NULL (gives 1.1% speedup).
2016-02-04 02:46:16 -08:00
Benjamin Peterson
3e47a1337c
merge 3.5
2016-01-01 11:56:35 -06:00
Benjamin Peterson
4e3dd51396
merge 3.4
2016-01-01 11:56:16 -06:00
Benjamin Peterson
630329e4ea
merge 3.3
2016-01-01 11:55:47 -06:00
Benjamin Peterson
0e617e22f0
remove some copyright notices supserseded by the toplevel ones
2016-01-01 11:53:47 -06:00
Serhiy Storchaka
a9406e77fa
Issue #25421 : __sizeof__ methods of builtin types now use dynamic basic size.
...
This allows sys.getsize() to work correctly with their subclasses with
__slots__ defined.
2015-12-19 20:07:11 +02:00
Serhiy Storchaka
5c4064e8bd
Issue #25421 : __sizeof__ methods of builtin types now use dynamic basic size.
...
This allows sys.getsize() to work correctly with their subclasses with
__slots__ defined.
2015-12-19 20:05:25 +02:00
Raymond Hettinger
e4495877dd
Minor tweek. Counting down rather than up reduces register pressure.
2015-12-15 00:42:30 -08:00
Raymond Hettinger
86d322f020
Undo inadvertent line swap
2015-12-13 19:27:17 -08:00
Raymond Hettinger
5088f6005f
Hoist constant expressions (so->table and so->mask) out of the inner-loop.
2015-12-13 18:45:01 -08:00
Raymond Hettinger
66f6238fca
Add assertion to verify the pre-condition in the comments.
2015-11-17 20:58:43 -08:00
Raymond Hettinger
6019c8ced0
Issue #25629 : Move set fill/used updates out of inner loop
2015-11-17 08:28:07 -08:00
Raymond Hettinger
4148195c45
Move the active entry multiplication to later in the hash calculation
2015-08-07 00:43:39 -07:00
Raymond Hettinger
b501a27ad8
Restore frozenset hash caching removed in cf707dd190a9
2015-08-06 22:15:22 -07:00
Raymond Hettinger
a286a51ae1
Fix comment typo
2015-08-01 11:07:11 -07:00
Raymond Hettinger
36c0500990
Tweak the comments
2015-08-01 10:57:42 -07:00
Raymond Hettinger
fbffdef47d
Issue #24762 : Speed-up frozenset_hash() and greatly beef-up the comments.
2015-08-01 09:53:00 -07:00
Raymond Hettinger
daffc916aa
Issue #24681 : Move the most likely test first in set_add_entry().
2015-07-31 07:58:56 -07:00
Raymond Hettinger
70559b5c20
Issue #24681 : Move the store of so->table to the code block where it is used.
2015-07-23 07:42:23 -04:00
Raymond Hettinger
ff9e18a863
Issue #24583 : Consolidate previous set object updates into a single function
...
with a single entry point, named exit points at the bottom, more self-evident
refcount adjustments, and a comment describing why the pre-increment was
necessary at all.
2015-07-20 07:34:05 -04:00
Raymond Hettinger
482c05cbb5
Issue #24583 : Fix refcount leak.
2015-07-20 01:23:32 -04:00
Raymond Hettinger
061091a7c5
Issue #24583 : Fix crash when set is mutated while being updated.
2015-07-15 23:54:02 -07:00
Raymond Hettinger
d702044bcd
merge
2015-07-15 23:52:29 -07:00
Raymond Hettinger
a3626bc5bd
Issue #24583 : Fix crash when set is mutated while being updated.
2015-07-15 23:50:14 -07:00
Raymond Hettinger
5d2385ff6f
Neaten-up a little bit.
2015-07-08 11:52:27 -07:00
Raymond Hettinger
9632a7d735
Issue 24581: Revert c9782a9ac031 pending a stronger test for mutation during iteration.
2015-07-07 15:29:24 -07:00
Raymond Hettinger
11ce8e6c37
Minor bit of factoring-out common code.
2015-07-06 19:08:49 -07:00
Raymond Hettinger
3dbc11cadd
Tighten-up code in the set iterator to use an entry pointer rather than indexing.
2015-07-06 19:03:01 -07:00
Raymond Hettinger
ef6bd7d963
Tighten-up code in set_next() to use an entry pointer rather than indexing.
2015-07-06 08:43:37 -07:00
Raymond Hettinger
b48d6a63ff
Bring related functions add/contains/discard together in the code.
2015-07-05 16:27:44 -07:00
Raymond Hettinger
73799b181e
Change add/contains/discard calls to pass the key and hash instead of an entry struct.
2015-07-05 16:06:10 -07:00
Raymond Hettinger
dc28d5a198
Clean-up call patterns for add/contains/discard to better match the caller's needs.
2015-07-05 10:03:20 -07:00
Raymond Hettinger
ac2ef65c32
Make the unicode equality test an external function rather than in-lining it.
...
The real benefit of the unicode specialized function comes from
bypassing the overhead of PyObject_RichCompareBool() and not
from being in-lined (especially since there was almost no shared
data between the caller and callee). Also, the in-lining was
having a negative effect on code generation for the callee.
2015-07-04 16:04:44 -07:00
Raymond Hettinger
e186c7674c
Make sure the dummy percentage calculation won't overflow.
2015-07-04 11:28:35 -07:00
Raymond Hettinger
c2480dc0c4
Minor cleanup.
2015-07-04 08:46:31 -07:00
Raymond Hettinger
b322326f48
Minor nit: Make the style of checking error return values more consistent.
2015-07-03 23:37:16 -07:00
Raymond Hettinger
4897300276
Minor factoring: move redundant resize scaling logic into the resize function.
2015-07-03 20:00:03 -07:00
Raymond Hettinger
3c1f52e829
Call set_lookkey() directly to avoid unnecessary memory spills and reloads.
2015-07-03 18:31:09 -07:00
Raymond Hettinger
15f0869609
Move insertion resize logic into set_insert_key().
...
Simplifies the code a little bit and does the resize check
only when a new key is added (giving a small speed up in
the case where the key already exists).
Fixes possible bug in set_merge() where the set_insert_key()
call relies on a big resize at the start to make enough room
for the keys but is vulnerable to a comparision callback that
could cause the table to shrink in the middle of the merge.
Also, changed the resize threshold from two-thirds of the
mask+1 to just two-thirds. The plus one offset gave no
real benefit (afterall, the two-thirds mark is just a
heuristic and isn't a precise cut-off).
2015-07-03 17:21:17 -07:00
Raymond Hettinger
2eff9e9441
Minor refactoring. Move reference count logic into function that adds entry.
2015-06-27 22:03:35 -07:00
Raymond Hettinger
91672617d5
Minor tweeak to tighten the inner-loop.
2015-06-26 02:50:21 -07:00
Raymond Hettinger
38bb95e49d
Minor code cleanup.
2015-06-24 01:22:19 -07:00
Raymond Hettinger
7e3592dca6
Harmonize the bottom of the outer loop with its entry point
...
giving a small simplification. Timings show that hash
pre-check seems only benefit the inner-loop (the linear probes).
2015-06-21 10:47:20 -07:00
Raymond Hettinger
6ee588f14e
Restore quick exit (no freeslot check) for common case (found null on first probe).
2015-06-20 21:39:51 -07:00
Yury Selivanov
7aa5341164
Reverting my previous commit.
...
Something went horribly wrong when I was doing `hg rebase`.
2015-05-30 10:57:56 -04:00
Serhiy Storchaka
e90982111a
Issue #24115 : Update uses of PyObject_IsTrue(), PyObject_Not(),
...
PyObject_IsInstance(), PyObject_RichCompareBool() and _PyDict_Contains()
to check for and handle errors correctly.
2015-05-30 17:48:54 +03:00
Serhiy Storchaka
ac5569b1fa
Issue #24115 : Update uses of PyObject_IsTrue(), PyObject_Not(),
...
PyObject_IsInstance(), PyObject_RichCompareBool() and _PyDict_Contains()
to check for and handle errors correctly.
2015-05-30 17:48:19 +03:00
Serhiy Storchaka
fa494fd883
Issue #24115 : Update uses of PyObject_IsTrue(), PyObject_Not(),
...
PyObject_IsInstance(), PyObject_RichCompareBool() and _PyDict_Contains()
to check for and handle errors correctly.
2015-05-30 17:45:22 +03:00
Raymond Hettinger
8651a50475
Issue #23359 : Specialize set_lookkey intoa lookup function and an insert function.
2015-05-27 10:37:20 -07:00
Raymond Hettinger
5af9e13c18
Minor stylistic and consistency cleanup.
2015-05-13 01:44:36 -07:00
Raymond Hettinger
1bd8d75be3
Issue #23290 : Optimize set_merge() for cases where the target is empty.
...
(Contributed by Serhiy Storchaka.)
2015-05-13 01:26:14 -07:00
Raymond Hettinger
438f9134cf
Mirco-optimizations to reduce register spills and reloads observed on CLANG and GCC.
2015-02-09 06:48:29 -06:00
Raymond Hettinger
8249282622
Minor code clean up.
2015-02-04 08:37:02 -08:00
Raymond Hettinger
06bb1226d1
Issue 23359: Reduce size of code in set_lookkey. Only do linear probes when there is no wrap-around.
...
Nice simplification contributed by Serhiy Storchaka :-)
2015-02-03 08:15:30 -08:00
Raymond Hettinger
c658d85487
Issue 23359: Tighten inner search loop for sets (don't and-mask every entry lookup).
2015-02-02 08:35:00 -08:00
Raymond Hettinger
59ecabd12a
Keep the definition of i consistent between set_lookkey() and set_insert_clean().
2015-01-31 02:45:12 -08:00
Raymond Hettinger
9edd753229
Minor tweak to improve code clarity.
2015-01-30 20:09:23 -08:00
Raymond Hettinger
06a1c8dfa0
Fix typo in a comment.
2015-01-30 18:02:15 -08:00
Raymond Hettinger
f8d1a31e70
Revert unintended part of the commit (the key==dummy test wasn't supposed to change).
2015-01-26 22:06:43 -08:00
Raymond Hettinger
a5ebbf6295
Remove unneeded dummy test from the set search loop (when the hashes match we know the key is not a dummy).
2015-01-26 21:54:35 -08:00
Raymond Hettinger
3037e84ad1
Issue #23269 : Tighten search_loop in set_insert_clean()
...
Instead of masking and shifting every loopup, move the wrap-around
test outside of the inner-loop.
2015-01-26 21:33:48 -08:00
Raymond Hettinger
b335dfe7fa
Set the hash values of dummy entries to -1. Improves quality of entry->hash == hash tests.
2015-01-25 16:38:52 -08:00
Raymond Hettinger
4d45c1069b
Update out-of-date comments.
2015-01-25 16:27:40 -08:00
Raymond Hettinger
93035c44fd
Issue #23119 : Simplify setobject by inlining the special case for unicode equality testing.
2015-01-25 16:12:49 -08:00
Raymond Hettinger
ed741d4ff0
A hybrid of and-masking and a conditional-set-to-zero produce even faster search loop.
2015-01-18 21:25:15 -08:00
Raymond Hettinger
bd9b200b87
Update copyright for 2015 updates.
2015-01-18 16:10:30 -08:00
Raymond Hettinger
9cd6a789c6
Clean-up, simplify, and slightly speed-up bounds logic in set_pop().
...
Elsewhere in the setobject.c code we do a bitwise-and with the mask
instead of using a conditional to reset to zero on wrap-around.
Using that same technique here use gives cleaner, faster, and more
consistent code.
2015-01-18 16:06:18 -08:00
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