[pypy-commit] pypy default: issue #1522
cfbolz
noreply at buildbot.pypy.org
Sat Oct 31 08:27:11 EDT 2015
Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch:
Changeset: r80492:fbabd7db9dad
Date: 2015-10-31 13:27 +0100
http://bitbucket.org/pypy/pypy/changeset/fbabd7db9dad/
Log: issue #1522
this fixes the problem of making a tiny set out of a really huge
iterable without generating a list out of the iterable first.
diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py
--- a/pypy/objspace/std/setobject.py
+++ b/pypy/objspace/std/setobject.py
@@ -1589,18 +1589,18 @@
w_set.sstorage = strategy.get_storage_from_unwrapped_list(intlist)
return
+ length_hint = space.length_hint(w_iterable, 0)
+
+ if jit.isconstant(length_hint):
+ return _pick_correct_strategy_unroll(space, w_set, w_iterable)
+
+ _create_from_iterable(space, w_set, w_iterable)
+
+
+ at jit.unroll_safe
+def _pick_correct_strategy_unroll(space, w_set, w_iterable):
+
iterable_w = space.listview(w_iterable)
-
- if len(iterable_w) == 0:
- w_set.strategy = strategy = space.fromcache(EmptySetStrategy)
- w_set.sstorage = strategy.get_empty_storage()
- return
-
- _pick_correct_strategy(space, w_set, iterable_w)
-
- at jit.look_inside_iff(lambda space, w_set, iterable_w:
- jit.loop_unrolling_heuristic(iterable_w, len(iterable_w), UNROLL_CUTOFF))
-def _pick_correct_strategy(space, w_set, iterable_w):
# check for integers
for w_item in iterable_w:
if type(w_item) is not W_IntObject:
@@ -1640,6 +1640,23 @@
w_set.strategy = space.fromcache(ObjectSetStrategy)
w_set.sstorage = w_set.strategy.get_storage_from_list(iterable_w)
+
+create_set_driver = jit.JitDriver(name='create_set',
+ greens=['tp', 'strategy'],
+ reds='auto')
+
+def _create_from_iterable(space, w_set, w_iterable):
+ iterable = space.iteriterable(w_iterable)
+ w_set.strategy = strategy = space.fromcache(EmptySetStrategy)
+ w_set.sstorage = strategy.get_empty_storage()
+
+ tp = space.type(w_iterable)
+ for w_item in space.iteriterable(w_iterable):
+ create_set_driver.jit_merge_point(tp=tp, strategy=w_set.strategy)
+ w_set.add(w_item)
+
+
+
init_signature = Signature(['some_iterable'], None, None)
init_defaults = [None]
def _initialize_set(space, w_obj, w_iterable=None):
More information about the pypy-commit
mailing list