Patchwork [2,of,3] pycompat: avoid using an extra function

login
register
mail settings
Submitter Pulkit Goyal
Date Aug. 13, 2016, 12:38 a.m.
Message ID <1141751d3fbffc136a0a.1471048705@pulkit-goyal>
Download mbox | patch
Permalink /patch/16266/
State Accepted
Headers show

Comments

Pulkit Goyal - Aug. 13, 2016, 12:38 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1471042302 -19800
#      Sat Aug 13 04:21:42 2016 +0530
# Node ID 1141751d3fbffc136a0afd6103c43532220f337d
# Parent  a200a82b16b7f73510930271dcca0e0691e14e69
pycompat: avoid using an extra function

We have a single line function which just lowercase the letters and replaces
"_" with "". Its better to avoid that function call. Moreover we calling this
 function around 33 times.

Patch

diff -r a200a82b16b7 -r 1141751d3fbf mercurial/pycompat.py
--- a/mercurial/pycompat.py	Sat Aug 13 03:03:01 2016 +0530
+++ b/mercurial/pycompat.py	Sat Aug 13 04:21:42 2016 +0530
@@ -41,11 +41,10 @@ 
 
     copies items from origin to alias
     """
-    def hgcase(item):
-        return item.replace('_', '').lower()
     for item in items:
         try:
-            setattr(alias, hgcase(item), getattr(origin, item))
+            lcase = item.replace('_', '').lower()
+            setattr(alias, lcase, getattr(origin, item))
         except AttributeError:
             pass