Patchwork [5,of,6] fileset: use set instead of list to mark predicates for efficiency (API)

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Dec. 21, 2015, 1:45 p.m.
Message ID <6aef05b2ae92f7c95261.1450705535@feefifofum>
Download mbox | patch
Permalink /patch/12209/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - Dec. 21, 2015, 1:45 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1450704676 -32400
#      Mon Dec 21 22:31:16 2015 +0900
# Node ID 6aef05b2ae92f7c9526147ec13fb02ea76a2f25e
# Parent  f60e365af7320d7ad130b4fbdd4aab8246b0e0a7
fileset: use set instead of list to mark predicates for efficiency (API)

This reduces cost of examining whether given predicate calls
'matchctx.status()' or 'matchctx.existing()' in 'getfileset()' at
runtime.

This kind of examination is used also in subsequent patch, which
detects unintentional 'matchctx.existing()' invocation per each
predicate evaluation.

Patch

diff --git a/mercurial/fileset.py b/mercurial/fileset.py
--- a/mercurial/fileset.py
+++ b/mercurial/fileset.py
@@ -138,10 +138,10 @@  def listset(mctx, a, b):
 symbols = {}
 
 # filesets using matchctx.status()
-_statuscallers = []
+_statuscallers = set()
 
 # filesets using matchctx.existing()
-_existingcallers = []
+_existingcallers = set()
 
 def predicate(decl, callstatus=False, callexisting=False):
     """Return a decorator for fileset predicate function
@@ -164,9 +164,9 @@  def predicate(decl, callstatus=False, ca
             name = decl
         symbols[name] = func
         if callstatus:
-            _statuscallers.append(name)
+            _statuscallers.add(name)
         if callexisting:
-            _existingcallers.append(name)
+            _existingcallers.add(name)
         if func.__doc__:
             func.__doc__ = "``%s``\n    %s" % (decl, func.__doc__.strip())
         return func