##// END OF EJS Templates
smartset: convert set to list lazily...
Jun Wu -
r31015:1076f7eb default
parent child Browse files
Show More
@@ -171,8 +171,12 b' class baseset(abstractsmartset):'
171 171 self._set = data
172 172 # set has no order we pick one for stability purpose
173 173 self._ascending = True
174 data = list(data)
175 self._list = data
174 # converting set to list has a cost, do it lazily
175 data = None
176 else:
177 data = list(data)
178 if data is not None:
179 self._list = data
176 180 self._datarepr = datarepr
177 181
178 182 @util.propertycache
@@ -185,6 +189,12 b' class baseset(abstractsmartset):'
185 189 asclist.sort()
186 190 return asclist
187 191
192 @util.propertycache
193 def _list(self):
194 # _list is only lazily constructed if we have _set
195 assert '_set' in self.__dict__
196 return list(self._set)
197
188 198 def __iter__(self):
189 199 if self._ascending is None:
190 200 return iter(self._list)
@@ -204,7 +214,7 b' class baseset(abstractsmartset):'
204 214 return self._set.__contains__
205 215
206 216 def __nonzero__(self):
207 return bool(self._list)
217 return bool(len(self))
208 218
209 219 def sort(self, reverse=False):
210 220 self._ascending = not bool(reverse)
@@ -218,7 +228,10 b' class baseset(abstractsmartset):'
218 228 self._istopo = False
219 229
220 230 def __len__(self):
221 return len(self._list)
231 if '_list' in self.__dict__:
232 return len(self._list)
233 else:
234 return len(self._set)
222 235
223 236 def isascending(self):
224 237 """Returns True if the collection is ascending order, False if not.
General Comments 0
You need to be logged in to leave comments. Login now