From c991db240ca8ea838c6acb0c8dc5300dca23c39e Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 11 Aug 2005 07:58:45 +0000 Subject: * Add short-circuit code for in-place operations with self (such as s|=s, s&=s, s-=s, or s^=s). Add related tests. * Improve names for several variables and functions. * Provide alternate table access functions (next, contains, add, and discard) that work with an entry argument instead of just a key. This improves set-vs-set operations because we already have a hash value for each key and can avoid unnecessary calls to PyObject_Hash(). Provides a 5% to 20% speed-up for quick hashing elements like strings and integers. Provides much more substantial improvements for slow hashing elements like tuples or objects defining a custom __hash__() function. * Have difference operations resize() when 1/5 of the elements are dummies. Formerly, it was 1/6. The new ratio triggers less frequently and only in cases that it can resize quicker and with greater benefit. The right answer is probably either 1/4, 1/5, or 1/6. Picked the middle value for an even trade-off between resize time and the space/time costs of dummy entries. --- Lib/test/test_set.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Lib/test/test_set.py') diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index cfb17b0ba2..a21d53c726 100644 --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -370,6 +370,18 @@ class TestSet(TestJointOps): else: self.assert_(c not in self.s) + def test_inplace_on_self(self): + t = self.s.copy() + t |= t + self.assertEqual(t, self.s) + t &= t + self.assertEqual(t, self.s) + t -= t + self.assertEqual(t, self.thetype()) + t = self.s.copy() + t ^= t + self.assertEqual(t, self.thetype()) + def test_weakref(self): s = self.thetype('gallahad') p = proxy(s) -- cgit v1.2.1