[PATCH 1 of 3 RFC] vfs: add "vfs" fields to localrepository for migration from "opener"

Simon King simon at simonking.org.uk
Thu Jun 28 03:04:36 CDT 2012


On 28 Jun 2012, at 08:41, FUJIWARA Katsunori <foozy at lares.dti.ne.jp> wrote:

> 
> At Wed, 27 Jun 2012 15:25:01 -0500,
> Matt Mackall wrote:
>> 
>> On Wed, 2012-06-27 at 17:19 +0900, FUJIWARA Katsunori wrote:
>>> At Tue, 26 Jun 2012 16:28:09 -0500,
>>> Matt Mackall wrote:
>>>> 
>>>> On Tue, 2012-06-26 at 12:59 +0200, Adrian Buehlmann wrote:
>>> 
>>>>> BTW, has anyone thought about renaming __call__ on the opener class to
>>>>> open? After all, vfs is not just an "opener" any more...
>>>> 
>>>> Adding an alias is fine.
>>> 
>>> Would "adding an alias" mean adding code like below ?
>>> 
>>>    def open(self, path, mode="r", text=False, atomictemp=False):
>>>        return self(path, mode, text, atomictemp)
>>> 
>>> (or "self.open = self.__call__" in "__init__()")
>> 
>> Why does it need to be in __init__?
> 
> I just think that:
> 
>  - defining "open()" causes indirect invocation of "__call__()" via
>    "open()", so it requires one more "function invocation" overhead
>    than direct "__call__()" invocation
> 
>  - setting "self.__call__" to "self.open" seems to reduce such
>    overhead (but it may be wrong, because I'm not so expert for
>    Python)
> 
> But, I don't know the other way to set "self.__call__" to "self.open"
> than doing it in "__init__()".
> 
> If there are any other good ways (or there is no need to mind such
> trivial overhead), please tell me and I'll do so.

At the class level (for example, immediately after defining __call__) you can simply add "open = __call__". This causes both names in the class dictionary to point at the same function object, so there is no overhead.

Hope that helps,

Simon


More information about the Mercurial-devel mailing list