mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Optimization to stop creating new small longs and use the
one previously stored. Issue 2417.
This commit is contained in:
parent
00c88f090d
commit
6e6f59b1c9
2 changed files with 46 additions and 22 deletions
|
@ -805,6 +805,24 @@ class LongTest(unittest.TestCase):
|
|||
self.assertRaises(ZeroDivisionError, eval, zero, namespace)
|
||||
|
||||
|
||||
def test_small_ints(self):
|
||||
for i in range(-5, 257):
|
||||
self.assertTrue(i is i + 0)
|
||||
self.assertTrue(i is i * 1)
|
||||
self.assertTrue(i is i - 0)
|
||||
self.assertTrue(i is i // 1)
|
||||
self.assertTrue(i is i & -1)
|
||||
self.assertTrue(i is i | 0)
|
||||
self.assertTrue(i is i ^ 0)
|
||||
self.assertTrue(i is ~~i)
|
||||
self.assertTrue(i is i**1)
|
||||
self.assertTrue(i is int(str(i)))
|
||||
self.assertTrue(i is i<<2>>2, str(i))
|
||||
# corner cases
|
||||
i = 1 << 70
|
||||
self.assertTrue(i - i is 0)
|
||||
self.assertTrue(0 * i is 0)
|
||||
|
||||
def test_main():
|
||||
support.run_unittest(LongTest)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue