[pypy-commit] pypy set-strategies: W_SetObject not takes w_iterable as init value instead of r_dict
l.diekmann
noreply at buildbot.pypy.org
Thu Nov 10 13:49:36 CET 2011
Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: set-strategies
Changeset: r49153:ae7f0c3075c5
Date: 2011-05-11 18:57 +0200
http://bitbucket.org/pypy/pypy/changeset/ae7f0c3075c5/
Log: W_SetObject not takes w_iterable as init value instead of r_dict
diff --git a/pypy/objspace/std/frozensettype.py b/pypy/objspace/std/frozensettype.py
--- a/pypy/objspace/std/frozensettype.py
+++ b/pypy/objspace/std/frozensettype.py
@@ -44,8 +44,7 @@
w_iterable is not None and type(w_iterable) is W_FrozensetObject):
return w_iterable
w_obj = space.allocate_instance(W_FrozensetObject, w_frozensettype)
- data = make_setdata_from_w_iterable(space, w_iterable)
- W_FrozensetObject.__init__(w_obj, space, data)
+ W_FrozensetObject.__init__(w_obj, space, w_iterable)
return w_obj
frozenset_typedef = StdTypeDef("frozenset",
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -233,10 +233,7 @@
return W_ComplexObject(x.real, x.imag)
if isinstance(x, set):
- rdict_w = r_dict(self.eq_w, self.hash_w)
- for item in x:
- rdict_w[self.wrap(item)] = None
- res = W_SetObject(self, rdict_w)
+ res = W_SetObject(self, [self.wrap(item) for item in x])
return res
if isinstance(x, frozenset):
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
@@ -47,12 +47,11 @@
return True
return False
- def __init__(w_self, space, setdata):
+ def __init__(w_self, space, w_iterable=None):
"""Initialize the set by taking ownership of 'setdata'."""
- assert setdata is not None
w_self.space = space #XXX less memory without this indirection?
#XXX in case of ObjectStrategy we can reuse the setdata object
- set_strategy_and_setdata(space, w_self, setdata.keys())
+ set_strategy_and_setdata(space, w_self, w_iterable)
def __repr__(w_self):
"""representation for debugging purposes"""
@@ -73,17 +72,17 @@
obj.sstorage = storage
return obj
- def _newobj(w_self, space, rdict_w=None):
+ def _newobj(w_self, space, w_iterable):
"""Make a new set or frozenset by taking ownership of 'rdict_w'."""
#return space.call(space.type(w_self),W_SetIterObject(rdict_w))
objtype = type(w_self)
if objtype is W_SetObject:
- obj = W_SetObject(space, rdict_w)
+ obj = W_SetObject(space, w_iterable)
elif objtype is W_FrozensetObject:
- obj = W_FrozensetObject(space, rdict_w)
+ obj = W_FrozensetObject(space, w_iterable)
else:
- itemiterator = space.iter(W_SetIterObject(rdict_w))
- obj = space.call_function(space.type(w_self),itemiterator)
+ itemiterator = space.iter(W_SetIterObject(w_iterable))
+ obj = space.call_function(space.type(w_self), itemiterator)
return obj
_lifeline_ = None
@@ -283,11 +282,9 @@
return True
def difference(self, w_set, w_other):
- result = w_set._newobj(self.space, newset(self.space))
+ result = w_set._newobj(self.space, None)
if not isinstance(w_other, W_BaseSetObject):
- w_temp = w_set._newobj(self.space, newset(self.space))
- set_strategy_and_setdata(self.space, w_temp, w_other)
- w_other = w_temp
+ w_other = w_set._newobj(self.space, w_other)
# lookup is faster when w_other is set
for w_key in w_set.getkeys():
if not w_other.has_key(w_key):
@@ -306,7 +303,7 @@
def symmetric_difference(self, w_set, w_other):
#XXX no wrapping when strategies are equal
- result = w_set._newobj(self.space, newset(self.space))
+ result = w_set._newobj(self.space, None)
for w_key in w_set.getkeys():
if not w_other.has_key(w_key):
result.add(w_key)
@@ -333,7 +330,7 @@
if w_set.length() > w_other.length():
return w_other.intersect(w_set)
- result = w_set._newobj(self.space, newset(self.space))
+ result = w_set._newobj(self.space, None)
items = self.cast_from_void_star(w_set.sstorage).keys()
#XXX do it without wrapping when strategies are equal
for key in items:
@@ -367,7 +364,7 @@
result = result.intersect(w_other)
else:
#XXX directly give w_other as argument to result2
- result2 = w_set._newobj(self.space, newset(self.space))
+ result2 = w_set._newobj(self.space, None)
for w_key in self.space.listview(w_other):
if result.has_key(w_key):
result2.add(w_key)
@@ -660,8 +657,7 @@
def eq__Set_settypedef(space, w_left, w_other):
# tested in test_buildinshortcut.py
#XXX do not make new setobject here
- w_other_as_set = w_left._newobj(space, newset(space))
- set_strategy_and_setdata(space, w_other_as_set, w_other)
+ w_other_as_set = w_left._newobj(space, w_other)
return space.wrap(w_left.equals(w_other))
eq__Set_frozensettypedef = eq__Set_settypedef
@@ -724,10 +720,7 @@
if space.is_w(w_left, w_other):
return space.w_True
- # this is faster when w_other is a set
- w_other_as_set = w_left._newobj(space, newset(space))
- set_strategy_and_setdata(space, w_other_as_set, w_other)
-
+ w_other_as_set = w_left._newobj(space, w_other)
return space.wrap(w_other_as_set.issuperset(w_left))
frozenset_issubset__Frozenset_ANY = set_issubset__Set_ANY
@@ -892,8 +885,7 @@
def set_symmetric_difference__Set_ANY(space, w_left, w_other):
#XXX since we need to iterate over both objects, create set
# from w_other so looking up items is fast
- w_other_as_set = w_left._newobj(space, newset(space))
- set_strategy_and_setdata(space, w_other_as_set, w_other)
+ w_other_as_set = w_left._newobj(space, w_other)
w_result = w_left.symmetric_difference(w_other_as_set)
return w_result
@@ -908,9 +900,7 @@
set_symmetric_difference_update__Set_Set
def set_symmetric_difference_update__Set_ANY(space, w_left, w_other):
- #XXX deal with iterables withouth turning them into sets
- w_other_as_set = w_left._newobj(space, newset(space))
- set_strategy_and_setdata(space, w_other_as_set, w_other)
+ w_other_as_set = w_left._newobj(space, w_other)
w_left.symmetric_difference_update(w_other_as_set)
def inplace_xor__Set_Set(space, w_left, w_other):
diff --git a/pypy/objspace/std/settype.py b/pypy/objspace/std/settype.py
--- a/pypy/objspace/std/settype.py
+++ b/pypy/objspace/std/settype.py
@@ -68,7 +68,7 @@
def descr__new__(space, w_settype, __args__):
from pypy.objspace.std.setobject import W_SetObject, newset
w_obj = space.allocate_instance(W_SetObject, w_settype)
- W_SetObject.__init__(w_obj, space, newset(space))
+ W_SetObject.__init__(w_obj, space)
return w_obj
set_typedef = StdTypeDef("set",
diff --git a/pypy/objspace/std/test/test_setobject.py b/pypy/objspace/std/test/test_setobject.py
--- a/pypy/objspace/std/test/test_setobject.py
+++ b/pypy/objspace/std/test/test_setobject.py
@@ -36,12 +36,11 @@
self.false = self.space.w_False
def test_and(self):
- s = W_SetObject(self.space, newset(self.space))
+ s = W_SetObject(self.space)
_initialize_set(self.space, s, self.word)
- t0 = W_SetObject(self.space, newset(self.space))
+ t0 = W_SetObject(self.space)
_initialize_set(self.space, t0, self.otherword)
- t1 = W_FrozensetObject(self.space,
- make_setdata_from_w_iterable(self.space, self.otherword))
+ t1 = W_FrozensetObject(self.space, self.otherword)
r0 = and__Set_Set(self.space, s, t0)
r1 = and__Set_Set(self.space, s, t1)
assert eq__Set_Set(self.space, r0, r1) == self.true
@@ -49,9 +48,9 @@
assert eq__Set_Set(self.space, r0, sr) == self.true
def test_compare(self):
- s = W_SetObject(self.space, newset(self.space))
+ s = W_SetObject(self.space)
_initialize_set(self.space, s, self.word)
- t = W_SetObject(self.space, newset(self.space))
+ t = W_SetObject(self.space)
_initialize_set(self.space, t, self.word)
assert self.space.eq_w(s,t)
u = self.space.wrap(set('simsalabim'))
More information about the pypy-commit
mailing list