[PATCH 2 of 4] revset: add __length_hint__ to smart classes
Durham Goode
durham at fb.com
Tue Sep 30 13:03:16 CDT 2014
On 9/29/14, 6:47 PM, Durham Goode wrote:
>
> On 9/29/14, 6:12 PM, Durham Goode wrote:
>> # HG changeset patch
>> # User Durham Goode <durham at fb.com>
>> # Date 1412036731 25200
>> # Mon Sep 29 17:25:31 2014 -0700
>> # Node ID 93be919300f04bfd26fd5294499fb62c96ba7f93
>> # Parent c6129c781a9f11be26191e64dcebf8d539c8c76a
>> revset: add __length_hint__ to smart classes
>>
>> This adds a __length_hint__ to the smart revset classes so we can
>> optimize at
>> runtime to avoid things like iterating over the large set and checking
>> containment against the small set when doing 'X & Y'.
>>
>> diff --git a/mercurial/revset.py b/mercurial/revset.py
>> --- a/mercurial/revset.py
>> +++ b/mercurial/revset.py
>> @@ -2204,6 +2204,9 @@ class baseset(list):
>> super(baseset, self).__init__(data)
>> self._set = None
>> + def __length_hint__(self):
>> + return len(self)
>> +
>> def ascending(self):
>> """Sorts the set in ascending order (in place).
>> @@ -2376,6 +2379,9 @@ class lazyset(object):
>> l = baseset([r for r in self])
>> return len(l)
>> + def __length_hint__(self):
>> + return self._subset.__length_hint__()
>> +
> I'm not 100% satisfied with this stuff. _subset is not guaranteed to
> be a smart set, and therefore might not even implement
> __length_hint__. But to fix it would require auditing every revset to
> ensure that subsets are always one of our smartsets.
I've sent a V2 that addresses this issue.
More information about the Mercurial-devel
mailing list