[PATCH resend] avoid .split() in for loops and use tuples instead

dsp at php.net dsp at php.net
Tue Dec 7 16:03:37 CST 2010


# HG changeset patch
# User David Soria Parra <dsp at php.net>
# Date 1291257786 -3600
# Node ID bafcb61041ebe15abaad35a415ea0831f02db719
# Parent  8c6b7a5f38c4585b1b2c2ceaffa8023f36a18479
avoid .split() in for loops and use tuples instead

split can be more readable for longer lists like the list in
dirstate.invalidate. As dirstate.invalidate is used in wlock() and therefoe
used heavily, I think it's worth avoiding a split there too.

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -230,7 +230,8 @@
             self._pl = p
 
     def invalidate(self):
-        for a in "_map _copymap _foldmap _branch _pl _dirs _ignore".split():
+        for a in ("_map", "_copymap", "_foldmap", "_branch", "_pl", "_dirs",
+                "_ignore"):
             if a in self.__dict__:
                 delattr(self, a)
         self._dirty = False
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -736,7 +736,7 @@
         self._branchcachetip = None
 
     def invalidate(self):
-        for a in "changelog manifest".split():
+        for a in ("changelog", "manifest"):
             if a in self.__dict__:
                 delattr(self, a)
         self.invalidatecaches()
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1098,7 +1098,7 @@
         if not defaults:
             defaults = {}
         now = makedate()
-        for part in "d mb yY HI M S".split():
+        for part in ("d", "mb", "yY", "HI", "M", "S"):
             if part not in defaults:
                 if part[0] in "HMS":
                     defaults[part] = "00"
@@ -1145,7 +1145,7 @@
 
     def upper(date):
         d = dict(mb="12", HI="23", M="59", S="59")
-        for days in "31 30 29".split():
+        for days in ("31", "30", "29"):
             try:
                 d["d"] = days
                 return parsedate(date, extendeddateformats, d)[0]


More information about the Mercurial-devel mailing list