Commit Graph

2153 Commits

Author SHA1 Message Date
Raymond Hettinger 27e403ebe9 Fixups to the hash function for frozensets.
* Non-zero initial value so that hash(frozenset()) != hash(0).
* Final permutation to differentiate nested sets.
* Add logic to make sure that -1 is not a possible hash value.
2004-06-10 21:38:41 +00:00
Raymond Hettinger 57c2d930f6 Add a final permutation step to the tuple hash function.
Prevents a collision pattern that occurs with nested tuples.
(Yitz Gale provided code that repeatably demonstrated the weakness.)
2004-06-10 18:42:15 +00:00
Martin v. Löwis 737ea82a5a Patch #774665: Make Python LC_NUMERIC agnostic. 2004-06-08 18:52:54 +00:00
Neal Norwitz b5d7702e5c whoops, I wanted that commented out by default, will add doc to Misc 2004-06-06 19:21:34 +00:00
Neal Norwitz 7eb3c9196d SF bug 881641, make it easier to use valgrind 2004-06-06 19:20:22 +00:00
Andrew M. Kuchling 41627bf78d Reword message 2004-06-05 19:49:12 +00:00
Andrew M. Kuchling 204d7861df Fix exception wording 2004-06-05 19:29:41 +00:00
Raymond Hettinger 4ec44e851d Replaced arbitrary addend in tuple_hash with one that is known to generate
many more prime multipliers and that performs well on collision tests.
2004-06-04 06:35:20 +00:00
Hye-Shik Chang 974ed7cfa5 - SF #962502: Add two more methods for unicode type; width() and
iswide() for east asian width manipulation. (Inspired by David
Goodger, Reviewed by Martin v. Loewis)
- Move _PyUnicode_TypeRecord.flags to the end of the struct so that
no padding is added for UCS-4 builds. (Suggested by Martin v. Loewis)
2004-06-02 16:49:17 +00:00
Martin v. Löwis e440e47e91 Patch #957398: Add public API for Generator Object/Type. 2004-06-01 15:22:42 +00:00
Raymond Hettinger 41bd02256f SF bug #942952: Weakness in tuple hash
(Basic approach and test concept by Tim Peters.)

* Improved the hash to reduce collisions.
* Added the torture test to the test suite.
2004-06-01 06:36:24 +00:00
Raymond Hettinger cb87bc8e7e Add weakref support to array.array and file objects. 2004-05-31 00:35:52 +00:00
Raymond Hettinger 691d80532b Make sets and deques weak referencable. 2004-05-30 07:26:47 +00:00
Walter Dörwald d70ad8a9d9 Update docstring for dict.update() to match the new realities. 2004-05-28 20:59:21 +00:00
Michael W. Hudson 08678a1055 Remove float_compare as per
[ 899109 ] 1==float('nan')

which can now finally be closed, I think.
2004-05-26 17:36:12 +00:00
Raymond Hettinger 10c660673e SF bug #952866: "can't multiply sequence *by* non-int"
Minor wording fix.
2004-05-12 21:35:06 +00:00
Raymond Hettinger fdfe618228 Nits:
- Neatened the braces in PyList_New().
- Made sure "indexerr" was initialized to NULL.
- Factored if blocks in PyList_Append().
- Made sure "allocated" is initialized in list_init().
2004-05-05 06:28:16 +00:00
Raymond Hettinger 0468e416c1 SF patch #947476: Apply freelist technique to lists
Re-use list object bodies.  Saves calls to malloc() and free() for
faster list instantiation and deallocation.
2004-05-05 05:37:53 +00:00
Thomas Heller 1328b52c6f Two new public API functions, Py_IncRef and Py_DecRef. Useful for
dynamic embedders of Python.
2004-04-22 17:23:49 +00:00
Raymond Hettinger 7892b1c651 * Add unittests for iterators that report their length
* Document the differences between them
* Fix corner cases covered by the unittests
* Use Py_RETURN_NONE where possible for dictionaries
2004-04-12 18:10:01 +00:00
Raymond Hettinger 45d0b5cc44 Use Py_RETURN_NONE macro where applicable. 2004-04-12 17:21:03 +00:00
Raymond Hettinger 501f02cd02 Small refactoring saving one function() and eliminating some indirection.
* Applied app1() to listappend().
* Inlined ins() into its one remaining caller.
2004-04-12 14:01:16 +00:00
Raymond Hettinger 40a03821ae * Specialize ins1() into app1() for appends. Saves several unnecessary
steps and further improves the speed of list append.

* Add guards to the list iterator length method to handle corner cases.
2004-04-12 13:05:09 +00:00
Hye-Shik Chang 4057483164 SF Patch #926375: Remove a useless UTF-16 support code that is never
been used. (Suggested by Martin v. Loewis)
2004-04-06 07:24:51 +00:00
Raymond Hettinger ed9192e2ae Improve previous checkin to use a slot check instead of equivalent
attribute name lookup.
2004-04-05 08:14:48 +00:00
Raymond Hettinger e2eda606a8 Improve accuracy of sequence and mapping checks. 2004-04-04 08:51:41 +00:00
Andrew MacIntyre 4e10ed3b86 If a file is opened with an explicit buffer size >= 1, repeated
close() calls would attempt to free() the buffer already free()ed on
the first close().     [bug introduced with patch #788249]

Making sure that the buffer is free()ed in file object deallocation is
a belt-n-braces bit of insurance against a memory leak.
2004-04-04 07:01:35 +00:00
Hye-Shik Chang ff365c931b Get rid of gcc warning. 2004-03-25 16:37:03 +00:00
Martin v. Löwis 093c100bd4 Correct code to advance ptr to be well-formed C. 2004-03-25 16:16:28 +00:00
Phillip J. Eby 91a968af76 Ensure super() lookup of descriptor from classmethod works (SF #743627) 2004-03-25 02:19:34 +00:00
Martin v. Löwis 321c9ab74c Intern __name__. 2004-03-23 18:40:15 +00:00
Armin Rigo 6fce78e07f Restored revision 2.87. 2004-03-21 22:29:05 +00:00
Tim Peters 1c3fd875b9 PyTuple_New(): vrbl i no longer referenced, so removed it (which kills
off a new compiler wng under MSVC6).
2004-03-21 21:35:41 +00:00
Armin Rigo 56716150e6 This is the fastest I could get on Intel GCC. I kept the memset() in to clear
the newly created tuples, but tuples added in the freelist are now cleared in
tupledealloc already (which is very cheap, because we are already
Py_XDECREF'ing all elements anyway).

Python should have a standard Py_ZAP macro like ZAP in pystate.c.
2004-03-21 20:27:49 +00:00
Nicholas Bastin abce8a681c Changed file.name to be the object passed as the 'name' argument to file()
Fixes SF Bug #773356
2004-03-21 20:24:07 +00:00
Raymond Hettinger 8183fa46a9 Fix typo in comment. 2004-03-21 17:35:06 +00:00
Raymond Hettinger 93d448198b Add identity shortcut to PyObject_RichCompareBool. 2004-03-21 17:01:44 +00:00
Tim Peters 5f112eb43b recursive_isinstance(), recursive_issubclass(): New code here returned
NULL in case of error, but the functions are declared to return int.
MSVC 6 properly complains about that.  Return -1 on error instead.
2004-03-21 16:59:09 +00:00
Brett Cannon 4f65331483 Limit the nesting depth of a tuple passed as the second argument to
isinstance() or issubclass() to the recursion limit of the interpreter.
2004-03-20 22:52:14 +00:00
Armin Rigo 70d172dda4 Get rid of listextend_internal() and explain why the special case
'a.extend(a)' isn't so special anyway.
2004-03-20 22:19:23 +00:00
Armin Rigo 7cdf3e8a8a memset() hunt continuing. This is a net win. 2004-03-20 21:35:09 +00:00
Armin Rigo 75be012cba memset() with small memory sizes just kill us. 2004-03-20 21:10:27 +00:00
Guido van Rossum 09240f65f8 GCC was complaining that 'value' in dictiter_iternextvalue() wasn't
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.
2004-03-20 19:11:58 +00:00
Fred Drake 086a0f79cd PyFile_WriteObject(): some of the local variables are only used when
Py_USING_UNICODE is defined
2004-03-19 15:22:36 +00:00
Raymond Hettinger 0690512a7d Factor out a double lookup. 2004-03-19 10:30:00 +00:00
Raymond Hettinger 435bf58b7b Make iterators length transparent where possible. 2004-03-18 22:43:10 +00:00
Raymond Hettinger 0ce6dc8530 Make the new dictionary iterators transparent with respect to length.
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.
2004-03-18 08:38:00 +00:00
Raymond Hettinger 019a148c72 Optimize dictionary iterators.
* 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.
2004-03-18 02:41:19 +00:00
Raymond Hettinger 4344278250 Dictionary optimizations:
* 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.
2004-03-17 21:55:03 +00:00
Raymond Hettinger 969d8c0c8c Add missing decref 2004-03-17 05:24:23 +00:00