Commit Graph

101 Commits

Author SHA1 Message Date
Tim Peters 6ee4234802 SF bug #439104: Tuple richcompares has code-typo.
Symptom:  (1, 2, 3) <= (1, 2) returned 1.
This was already fixed in CVS for tuples, but an isomorphic error was in
the list richcompare code.
2001-07-06 17:45:43 +00:00
Tim Peters a7259597f1 SF bug 433228: repr(list) woes when len(list) big.
Gave Python linear-time repr() implementations for dicts, lists, strings.
This means, e.g., that repr(range(50000)) is no longer 50x slower than
pprint.pprint() in 2.2 <wink>.

I don't consider this a bugfix candidate, as it's a performance boost.

Added _PyString_Join() to the internal string API.  If we want that in the
public API, fine, but then it requires runtime error checks instead of
asserts.
2001-06-16 05:11:17 +00:00
Tim Peters 1af03e98d9 Change list.extend() error msgs and NEWS to reflect that list.extend()
now takes any iterable argument, not only sequences.

NEEDS DOC CHANGES -- but I don't think we settled on a concise way to
say this stuff.
2001-05-26 19:37:54 +00:00
Tim Peters 442914d265 Cruft cleanup: removed the #ifdef'ery in support of compiling to allow
multi-argument list.append(1, 2, 3) (as opposed to .append((1,2,3))).
2001-05-26 05:50:03 +00:00
Tim Peters 65b8b84839 roundupsize() and friends: fiddle over-allocation strategy for list
resizing.

Accurate timings are impossible on my Win98SE box, but this is obviously
faster even on this box for reasonable list.append() cases.  I give
credit for this not to the resizing strategy but to getting rid of integer
multiplication and divsion (in favor of shifting) when computing the
rounded-up size.

For unreasonable list.append() cases, Win98SE now displays linear behavior
for one-at-time appends up to a list with about 35 million elements.  Then
it dies with a MemoryError, due to fatally fragmented *address space*
(there's plenty of VM available, but by this point Win9X has broken user
space into many distinct heaps none of which has enough contiguous space
left to resize the list, and for whatever reason Win9x isn't coalescing
the dead heaps).  Before the patch it got a MemoryError for the same
reason, but once the list reached about 2 million elements.

Haven't yet tried on Win2K but have high hopes extreme list.append()
will be much better behaved now (NT & Win2K didn't fragment address space,
but suffered obvious quadratic-time behavior before as lists got large).

For other systems I'm relying on common sense:  replacing integer * and /
by << and >> can't plausibly hurt, the number of function calls hasn't
changed, and the total operation count for reasonably small lists is about
the same (while the operations are cheaper now).
2001-05-26 05:28:40 +00:00
Guido van Rossum b86c549c7c Fix core dump whenever PyList_Reverse() was called.
This fixes SF bug #132008, reported by Warren J. Hack.

The copyright for this patch (and this patch only) belongs to CNRI, as
part of the (yet to be issued) 1.6.1 release.

This is now checked into the HEAD branch.  Tim will check in a test
case to check for this specific bug, and an assertion in
PyArgs_ParseTuple() to catch similar bugs in the future.
2001-02-12 22:06:02 +00:00
Guido van Rossum 65e1cea6e3 Convert to rich comparisons:
- sort's docompare() calls RichCompare(Py_LT).

- list_contains(), list_index(), listcount(), listremove() call
  RichCompare(Py_EQ).

- Get rid of list_compare(), in favor of new list_richcompare().  The
  latter does some nice shortcuts, like when == or != is requested, it
  first compares the lengths for trivial accept/reject.  Then it goes
  over the items until it finds an index where the items differe; then
  it does more shortcut magic to minimize the number of additional
  comparisons.

- Aligned the comments for large struct initializers.
2001-01-17 22:11:59 +00:00
Jeremy Hylton db60bb5aad fix leak 2001-01-03 22:32:16 +00:00
Tim Peters 0e76ab2ecc Use METH_VARARGS instead of "1" in list method table. 2000-12-13 22:35:46 +00:00
Fred Drake d5fadf75e4 Rationalize use of limits.h, moving the inclusion to Python.h.
Add definitions of INT_MAX and LONG_MAX to pyport.h.
Remove includes of limits.h and conditional definitions of INT_MAX
and LONG_MAX elsewhere.

This closes SourceForge patch #101659 and bug #115323.
2000-09-26 05:46:01 +00:00
Guido van Rossum 8586991099 REMOVED all CWI, CNRI and BeOpen copyright markings.
This should match the situation in the 1.6b1 tree.
2000-09-01 23:29:29 +00:00
Thomas Wouters e289e0bd0c Support for the in-place operations introduced by augmented assignment. Only
the list object supports this currently, but other candidates are
gladly accepted (like arraymodule and such.)
2000-08-24 20:08:19 +00:00
Jack Jansen e979160f5e Added include for limits.h 2000-08-22 21:51:22 +00:00
Trent Mick a584664134 Check for overflow in list object insertion and raise OverflowError.
see: http://www.python.org/pipermail/python-dev/2000-August/014971.html
2000-08-13 22:47:45 +00:00
Thomas Wouters 334fb8985b Use 'void' directly instead of the ANY #define, now that all code is ANSI C.
Leave the actual #define in for API compatibility.
2000-07-25 12:56:38 +00:00
Vladimir Marangozov 467a67e74d Fix in PyList_New(). With GC enabled and when out of memory,
free() the GC pointer, not the object pointer.
2000-07-15 03:31:31 +00:00
Jeremy Hylton 03657cfdb0 replace PyXXX_Length calls with PyXXX_Size calls 2000-07-12 13:05:33 +00:00
Fred Drake a2f5511941 ANSI-fication of the sources. 2000-07-09 15:16:51 +00:00
Guido van Rossum 4cc6ac7b87 Neil Schemenauer: small fixes for GC 2000-07-01 01:00:38 +00:00
Guido van Rossum ffcc3813d8 Change copyright notice - 2nd try. 2000-06-30 23:58:06 +00:00
Guido van Rossum fd71b9e9d4 Change copyright notice. 2000-06-30 23:50:40 +00:00
Jeremy Hylton c5007aa5c3 final patches from Neil Schemenauer for garbage collection 2000-06-30 05:02:53 +00:00
Jeremy Hylton d08b4c4524 part 2 of Neil Schemenauer's GC patches:
This patch modifies the type structures of objects that
participate in GC.  The object's tp_basicsize is increased when
GC is enabled.  GC information is prefixed to the object to
maintain binary compatibility.  GC objects also define the
tp_flag Py_TPFLAGS_GC.
2000-06-23 19:37:02 +00:00
Jeremy Hylton 8caad49c30 Round 1 of Neil Schemenauer's GC patches:
This patch adds the type methods traverse and clear necessary for GC
implementation.
2000-06-23 14:18:11 +00:00
Andrew M. Kuchling 74042d6e5d Patch from /F:
this patch introduces PySequence_Fast and PySequence_Fast_GET_ITEM,
and modifies the list.extend method to accept any kind of sequence.
2000-06-18 18:43:14 +00:00
Fred Drake 56780257c6 Thomas Wouters <thomas@xs4all.net>:
The following patch adds "sq_contains" support to rangeobject, and enables
the already-written support for sq_contains in listobject and tupleobject.

The rangeobject "contains" code should be a bit more efficient than the
current default "in" implementation ;-) It might not get used much, but it's
not that much to add.

listobject.c and tupleobject.c already had code for sq_contains, and the
proper struct member was set, but the PyType structure was not extended to
include tp_flags, so the object-specific code was not getting called (Go
ahead, test it ;-). I also did this for the immutable_list_type in
listobject.c, eventhough it is probably never used. Symmetry and all that.
2000-06-15 14:50:20 +00:00
Fred Drake 914a2edb24 Improve TypeError exception message for list catenation. 2000-06-01 14:31:03 +00:00
Fred Drake b6a9ada757 Michael Hudson <mwh21@cam.ac.uk>:
Removed PyErr_BadArgument() calls and replaced them with more useful
error messages.
2000-06-01 03:12:13 +00:00
Guido van Rossum b18618dab7 Vladimir Marangozov's long-awaited malloc restructuring.
For more comments, read the patches@python.org archives.
For documentation read the comments in mymalloc.h and objimpl.h.

(This is not exactly what Vladimir posted to the patches list; I've
made a few changes, and Vladimir sent me a fix in private email for a
problem that only occurs in debug mode.  I'm also holding back on his
change to main.c, which seems unnecessary to me.)
2000-05-03 23:44:39 +00:00
Jeremy Hylton 37b1a26c89 add list_contains and tuplecontains: efficient implementations of tp_contains 2000-04-27 21:41:03 +00:00
Guido van Rossum d724b23420 Christian Tismer's "trashcan" patch:
Added wrapping macros to dictobject.c, listobject.c, tupleobject.c,
frameobject.c, traceback.c that safely prevends core dumps
on stack overflow. Macros and functions in object.c, object.h.
The method is an "elevator destructor" that turns cascading
deletes into tail recursive behavior when some limit is hit.
2000-03-13 16:01:29 +00:00
Guido van Rossum ef93b87f1c Added Christian Tismer's patch to allow list.append(a,b,c) back --
with a twist: you have to define NO_STRICT_LIST_APPEND manually
to enable multi-arg append().
2000-03-13 15:41:59 +00:00
Guido van Rossum c00a938be8 OKOK, Greg's right, I should've used the :name option in the argument
format strings.
2000-02-24 21:48:29 +00:00
Guido van Rossum 4aa24f9979 Made all list methods use PyArg_ParseTuple(), for more accurate
diagnostics.

*** INCOMPATIBLE CHANGE: This changes append(), remove(), index(), and
*** count() to require exactly one argument -- previously, multiple
*** arguments were silently assumed to be a tuple.
2000-02-24 15:23:03 +00:00
Guido van Rossum bffd683f73 The rest of the changes by Trent Mick and Dale Nagata for warning-free
compilation on NT Alpha.  Mostly added casts etc.
2000-01-20 22:32:56 +00:00
Guido van Rossum fa71701d46 When deallocating a list, DECREF the items from the end back to the start. 1999-06-09 15:19:34 +00:00
Guido van Rossum 9bcd1d7931 Improve text of some error messages, as suggested by Sean Reifschneider. 1999-04-19 17:44:39 +00:00
Guido van Rossum 3aa23fdd47 Jim Ahlstrom patch: cutoff should be a long for machines with 16-bit
ints.  (In theory, other variables should be widened to long as well,
but this won't ever be needed, since the len of a list is still an
int.)
1999-01-14 19:01:53 +00:00
Barry Warsaw dedf6d6804 listextend(): New method which implements L.extend(L2). 1998-10-09 16:37:25 +00:00
Guido van Rossum 2ccaf6f2f9 Remove a redundant check from list_slice() and list_ass_slice().
Noted by Greg Stein.
1998-10-07 13:24:13 +00:00
Guido van Rossum 3dd7f3fef0 Added doc strings for methods and a new pop() method. 1998-06-30 15:36:32 +00:00
Guido van Rossum 4281258b5f Minor cleanup by Tim after my changes:
+ Took the "list" argument out of the other functions that no longer need
it.  This speeds things up a little more.

+ Small comment changes in accord with that.

+ Exploited the now-safe ability to cache values in the partitioning loop.
Makes no timing difference on my flavor of Pentium, but this machine ran out
of registers 12 iterations ago.  It should yield a small speedup on a RISC
machine, and not hurt in any case.
1998-06-17 14:15:44 +00:00
Guido van Rossum 4c4e7df755 Tim's latest, with some of my changes (also a TP suggestion) added:
instead of testing whether the list changed size after each
comparison, temporarily set the type of the list to an immutable list
type.  This should allow continued use of the list for legitimate
purposes but disallows all operations that can change it in any way.
(Changes to the internals of list items are not caught, of cause;
that's not possible to detect, and it's not necessary to protect the
sort code, either.)
1998-06-16 15:18:28 +00:00
Guido van Rossum a119c0dd5e Tim's revision of the previous patch. He also added some sparts to
the median-of-three code to get a few percent back.
1998-05-29 17:56:32 +00:00
Guido van Rossum ae621ff7b7 Guard against changes in the list size during a compare or sort. 1998-05-28 20:18:46 +00:00
Guido van Rossum 9be628338d Tim's quicksort on May 25. 1998-05-26 15:06:32 +00:00
Guido van Rossum ed7adcff73 Tim's quicksort on May 13. 1998-05-13 21:21:24 +00:00
Guido van Rossum b7057640d1 Tim's quicksort on May 10. 1998-05-13 21:20:49 +00:00
Guido van Rossum e32907df67 Get rid of the unused ifdefed-out old sort code. 1998-04-28 17:54:03 +00:00
Guido van Rossum 82e6a8f80d Quicksort retuned by Tim Peters. 1998-04-28 13:17:56 +00:00