Mercurial > public > mercurial-scm > hg
comparison mercurial/smartset.py @ 31066:c962bb6af909
smartset: preserve istopo for baseset operations
This is a follow-up of "smartset: use native set operations as fast paths".
It's more correct to just preserve the "istopo" information for "&" and "-"
operations, like what filteredset does.
author | Jun Wu <quark@fb.com> |
---|---|
date | Tue, 21 Feb 2017 16:29:31 -0800 |
parents | 2d1bf84046f6 |
children | 90fb0193f187 |
comparison
equal
deleted
inserted
replaced
31062:88203f26ea57 | 31066:c962bb6af909 |
---|---|
201 >>> ys.sort() | 201 >>> ys.sort() |
202 >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]] | 202 >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]] |
203 [[7, 6, 4, 0, 3, 5], [7, 6], [4, 0]] | 203 [[7, 6, 4, 0, 3, 5], [7, 6], [4, 0]] |
204 >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]] | 204 >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]] |
205 ['addset', 'baseset', 'baseset'] | 205 ['addset', 'baseset', 'baseset'] |
206 | |
207 istopo is preserved across set operations | |
208 >>> xs = baseset(set(x), istopo=True) | |
209 >>> rs = xs & ys | |
210 >>> type(rs).__name__ | |
211 'baseset' | |
212 >>> rs._istopo | |
213 True | |
206 """ | 214 """ |
207 def __init__(self, data=(), datarepr=None, istopo=False): | 215 def __init__(self, data=(), datarepr=None, istopo=False): |
208 """ | 216 """ |
209 datarepr: a tuple of (format, obj, ...), a function or an object that | 217 datarepr: a tuple of (format, obj, ...), a function or an object that |
210 provides a printable representation of the given data. | 218 provides a printable representation of the given data. |
324 | 332 |
325 def _fastsetop(self, other, op): | 333 def _fastsetop(self, other, op): |
326 # try to use native set operations as fast paths | 334 # try to use native set operations as fast paths |
327 if (type(other) is baseset and '_set' in other.__dict__ and '_set' in | 335 if (type(other) is baseset and '_set' in other.__dict__ and '_set' in |
328 self.__dict__ and self._ascending is not None): | 336 self.__dict__ and self._ascending is not None): |
329 s = baseset(data=getattr(self._set, op)(other._set)) | 337 s = baseset(data=getattr(self._set, op)(other._set), |
338 istopo=self._istopo) | |
330 s._ascending = self._ascending | 339 s._ascending = self._ascending |
331 else: | 340 else: |
332 s = getattr(super(baseset, self), op)(other) | 341 s = getattr(super(baseset, self), op)(other) |
333 return s | 342 return s |
334 | 343 |