summaryrefslogtreecommitdiffstats
path: root/Objects/dictobject.c
Commit message (Collapse)AuthorAgeFilesLines
* Fixed English in a comment; trimmed trailing whitespace;Tim Peters2006-01-011-11/+11
| | | | no code changes.
* Convert iterator __len__() methods to a private API.Raymond Hettinger2005-09-241-9/+18
|
* Fix nits.Raymond Hettinger2005-08-171-2/+2
|
* SF patch #1200051: Small optimization for PyDict_Merge()Raymond Hettinger2005-05-141-0/+6
| | | | (Contributed by Barry Warsaw and Matt Messier.)
* SF bug #1183742: PyDict_Copy() can return non-NULL value on errorRaymond Hettinger2005-04-151-1/+1
|
* Code simplification -- eliminate lookup when value is known in advance.Raymond Hettinger2005-02-051-2/+4
|
* Moved SunPro warning suppression into pyport.h and out of individualNicholas Bastin2004-07-151-4/+0
| | | | modules and objects.
* Disabling end-of-loop code not reached warning on SunProNicholas Bastin2004-06-181-0/+4
|
* Update docstring for dict.update() to match the new realities.Walter Dörwald2004-05-281-1/+2
|
* * Add unittests for iterators that report their lengthRaymond Hettinger2004-04-121-7/+7
| | | | | | * Document the differences between them * Fix corner cases covered by the unittests * Use Py_RETURN_NONE where possible for dictionaries
* GCC was complaining that 'value' in dictiter_iternextvalue() wasn'tGuido van Rossum2004-03-201-5/+6
| | | | | | necessarily always set before used. Between Tim, Armin & me we couldn't prove GCC wrong, so we decided to fix the algorithm. This version is Armin's.
* Factor out a double lookup.Raymond Hettinger2004-03-191-2/+1
|
* Make the new dictionary iterators transparent with respect to length.Raymond Hettinger2004-03-181-4/+20
| | | | | | This gives another 30% speedup for operations such as map(func, d.iteritems()) or list(d.iteritems()) which can both take advantage of length information when provided.
* Optimize dictionary iterators.Raymond Hettinger2004-03-181-57/+202
| | | | | | | | | | | | | | | | | | * Split into three separate types that share everything except the code for iternext. Saves run time decision making and allows each iternext function to be specialized. * Inlined PyDict_Next(). In addition to saving a function call, this allows a redundant test to be eliminated and further specialization of the code for the unique needs of each iterator type. * Created a reusable result tuple for iteritems(). Saves the malloc time for tuples when the previous result was not kept by client code (this is the typical use case for iteritems). If the client code does keep the reference, then a new tuple is created. Results in a 20% to 30% speedup depending on the size and sparsity of the dictionary.
* Dictionary optimizations:Raymond Hettinger2004-03-171-24/+61
| | | | | | | | | | | | * Factored constant structure references out of the inner loops for PyDict_Next(), dict_keys(), dict_values(), and dict_items(). Gave measurable speedups to each (the improvement varies depending on the sparseness of the dictionary being measured). * Added a freelist scheme styled after that for tuples. Saves around 80% of the calls to malloc and free. About 10% of the time, the previous dictionary was completely empty; in those cases, the dictionary initialization with memset() can be skipped.
* Factor out code common to PyDict_Copy() and PyDict_Merge().Raymond Hettinger2004-03-081-20/+6
|
* SF #904720: dict.update should take a 2-tuple sequence like dict.__init_Raymond Hettinger2004-03-041-18/+24
| | | | | | | | (Championed by Bob Ippolito.) The update() method for mappings now accepts all the same argument forms as the dict() constructor. This includes item lists and/or keyword arguments.
* Oops. Return -1 to distinguish error from empty dict.Jeremy Hylton2004-02-171-1/+1
| | | | | This change probably isn't work a bug fix. It's unlikely that anyone was calling this method without passing it a real dict.
* Simplify previous checkin -- a new function was not needed.Raymond Hettinger2003-12-131-26/+1
|
* * Added a new method flag, METH_COEXIST.Raymond Hettinger2003-12-131-0/+34
| | | | | * Used the flag to optimize set.__contains__(), dict.__contains__(), dict.__getitem__(), and list.__getitem__().
* Expose dict_contains() and PyDict_Contains() with is about 10% fasterRaymond Hettinger2003-11-251-3/+4
| | | | | | | than PySequence_Contains() and more clearly applicable to dicts. Apply the new function in setobject.c where __contains__ checking is ubiquitous.
* SF patch #798467: Update docstring of has_key for bool changesRaymond Hettinger2003-09-011-1/+1
| | | | (Contributed by George Yoshida.)
* SF patch #729395: Dictionary tuningRaymond Hettinger2003-05-071-2/+2
| | | | | Adjust resize argument for dict.update() and dict.copy(). Extends the previous change to dict.__setitem__().
* SF patch #729395: Dictionary tuningRaymond Hettinger2003-05-051-10/+16
| | | | | | | | | | * Increase dictionary growth rate resulting in more sparse dictionaries, fewer lookup collisions, increased memory use, and better cache performance. For dicts with over 50k entries, keep the current growth rate in case an application is suffering from tight memory constraints. * Set the most common case (no resize) to fall-through the test.
* Add a reference to dictnotes.txt. It does no good if you don't know it'sRaymond Hettinger2003-05-031-0/+6
| | | | there or where to find it.
* Renamed PyObject_GenericGetIter to PyObject_SelfIterRaymond Hettinger2003-03-171-1/+1
| | | | | | to more accurately describe what the function does. Suggested by Thomas Wouters.
* Created PyObject_GenericGetIter().Raymond Hettinger2003-03-171-8/+1
| | | | Factors out the common case of returning self.
* SF patch #693753: fix for bug 639806: default for dict.popRaymond Hettinger2003-03-061-3/+15
| | | | (contributed by Michael Stone.)
* Add closing ) in commentNeal Norwitz2003-02-151-1/+1
|
* cPickle.c, load_build(): Taught cPickle how to pick apartTim Peters2003-02-151-1/+11
| | | | | | | | | | | | | | | | | | the optional proto 2 slot state. pickle.py, load_build(): CAUTION: Noted that cPickle's load_build and pickle's load_build really don't do the same things with the state, and didn't before this patch either. cPickle never tries to do .update(), and has no backoff if instance.__dict__ can't be retrieved. There are no tests that can tell the difference, and part of what cPickle's load_build() did looked accidental to me, so I don't know what the true intent is here. pickletester.py, test_pickle.py: Got rid of the hack for exempting cPickle from running some of the proto 2 tests. dictobject.c, PyDict_Next(): documented intended use.
* SF patch #659536: Use PyArg_UnpackTuple where possible.Raymond Hettinger2002-12-291-4/+4
| | | | | | | Obtain cleaner coding and a system wide performance boost by using the fast, pre-parsed PyArg_Unpack function instead of PyArg_ParseTuple function which is driven by a format string.
* Constify char* API. Fixes #651363. 2.2 candidate.Martin v. Löwis2002-12-111-3/+3
|
* SF 548651: Fix the METH_CLASS implementation.Tim Peters2002-12-091-3/+2
| | | | | | | Most of these patches are from Thomas Heller, with long lines folded by Tim. The change to test_descr.py is from Guido. See the bug report. Not a bugfix candidate -- METH_CLASS is new in 2.3.
* Remove assumption that cls is a subclass of dict.Raymond Hettinger2002-12-071-7/+1
| | | | Simplifies the code and gets Just van Rossum's example to work.
* Replace BadInternalCall with TypeError. Add a test case. Fix whitespace.Raymond Hettinger2002-12-041-2/+3
| | | | | | | Just van Rossum showed a weird, but clever way for pure python code to trigger the BadInternalCall. The C code had assumed that calling a class constructor would return an instance of that class; however, classes that abuse __new__ can invalidate that assumption.
* Add missing decrefNeal Norwitz2002-11-271-0/+1
|
* SF Patch 643443. Added dict.fromkeys(iterable, value=None), a classRaymond Hettinger2002-11-271-0/+56
| | | | method for constructing new dictionaries from sequences of keys.
* Patch #642500 with slight modifications: allow keyword arguments inJust van Rossum2002-11-231-5/+7
| | | | | | | dict() constructor. Example: >>> dict(a=1, b=2) {'a': 1, 'b': 2} >>>
* In doc strings, use 'k in D' rather than D.has_key(k).Guido van Rossum2002-09-041-2/+2
|
* SF patch 576101, by Oren Tirosh: alternative implementation ofGuido van Rossum2002-08-191-9/+3
| | | | | | | | interning. I modified Oren's patch significantly, but the basic idea and most of the implementation is unchanged. Interned strings created with PyString_InternInPlace() are now mortal, and you must keep a reference to the resulting string around; use the new function PyString_InternImmortal() to create immortal interned strings.
* staticforward bites the dust.Jeremy Hylton2002-07-171-1/+1
| | | | | | | | | | | | | | | The staticforward define was needed to support certain broken C compilers (notably SCO ODT 3.0, perhaps early AIX as well) botched the static keyword when it was used with a forward declaration of a static initialized structure. Standard C allows the forward declaration with static, and we've decided to stop catering to broken C compilers. (In fact, we expect that the compilers are all fixed eight years later.) I'm leaving staticforward and statichere defined in object.h as static. This is only for backwards compatibility with C extensions that might still use it. XXX I haven't updated the documentation.
* Make StopIteration a sink state. This is done by clearing out theGuido van Rossum2002-07-161-28/+11
| | | | | | | | | | di_dict field when the end of the list is reached. Also make the error ("dictionary changed size during iteration") a sticky state. Also remove the next() method -- one is supplied automatically by PyType_Ready() because the tp_iternext slot is set. That's a good thing, because the implementation given here was buggy (it never raised StopIteration).
* Patch #568124: Add doc string macros.Martin v. Löwis2002-06-131-30/+30
|
* Add Raymond Hettinger's d.pop(). See SF patch 539949.Guido van Rossum2002-04-121-0/+38
|
* PyObject_GC_Del and PyObject_Del can now be used as a functionNeil Schemenauer2002-04-121-3/+3
| | | | | | designators. Remove PyMalloc_New.
* Add the 'bool' type and its values 'False' and 'True', as described inGuido van Rossum2002-04-031-1/+1
| | | | | | | | | | | | | PEP 285. Everything described in the PEP is here, and there is even some documentation. I had to fix 12 unit tests; all but one of these were printing Boolean outcomes that changed from 0/1 to False/True. (The exception is test_unicode.py, which did a type(x) == type(y) style comparison. I could've fixed that with a single line using issubtype(x, type(y)), but instead chose to be explicit about those places where a bool is expected. Still to do: perhaps more documentation; change standard library modules to return False/True from predicates.
* Remove the CACHE_HASH and INTERN_STRINGS preprocessor symbols.Tim Peters2002-03-291-34/+8
|
* This is Neil's fix for SF bug 535905 (Evil Trashcan and GC interaction).Guido van Rossum2002-03-281-1/+1
| | | | | | | | The fix makes it possible to call PyObject_GC_UnTrack() more than once on the same object, and then move the PyObject_GC_UnTrack() call to *before* the trashcan code is invoked. BUGFIX CANDIDATE!
* Use pymalloc if it's enabled.Neil Schemenauer2002-03-221-2/+2
|
* SF bug #491415 PyDict_UpdateFromSeq2() unusedTim Peters2001-12-111-8/+2
| | | | | | | PyDict_UpdateFromSeq2(): removed it. PyDict_MergeFromSeq2(): made it public and documented it. PyDict_Merge() docs: updated to reveal <wink> that the second argument can be any mapping object.