Patchwork [05,of,10] bundlerepo: inline inbundle()

login
register
mail settings
Submitter Mads Kiilerich
Date Jan. 16, 2013, 7:57 p.m.
Message ID <c2b44c239c909a81fcc6.1358366249@mk-desktop>
Download mbox | patch
Permalink /patch/666/
State Accepted
Commit c448562ad85b60a26eb2c814952e6facef2e9c03
Headers show

Comments

Mads Kiilerich - Jan. 16, 2013, 7:57 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1358365301 -3600
# Node ID c2b44c239c909a81fcc6bedc78125ac5c2f43aa8
# Parent  405be105e67022c56c19265316612f5784b12d46
bundlerepo: inline inbundle()

It didn't make it faster, it didn't make the code smaller, it didn't make the
code simpler.

-1 is never in basemap.
tonfa - Jan. 16, 2013, 8:20 p.m.
LGTM


On Wed, Jan 16, 2013 at 8:57 PM, Mads Kiilerich <mads@kiilerich.com> wrote:

> # HG changeset patch
> # User Mads Kiilerich <madski@unity3d.com>
> # Date 1358365301 -3600
> # Node ID c2b44c239c909a81fcc6bedc78125ac5c2f43aa8
> # Parent  405be105e67022c56c19265316612f5784b12d46
> bundlerepo: inline inbundle()
>
> It didn't make it faster, it didn't make the code smaller, it didn't make
> the
> code simpler.
>
> -1 is never in basemap.
>
> diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
> --- a/mercurial/bundlerepo.py
> +++ b/mercurial/bundlerepo.py
> @@ -70,29 +70,23 @@
>              chain = node
>              n += 1
>
> -    def inbundle(self, rev):
> -        """is rev from the bundle"""
> -        if rev < 0:
> -            return False
> -        return rev in self.basemap
> -
>      def _chunk(self, rev):
>          # Warning: in case of bundle, the diff is against self.basemap,
>          # not against rev - 1
>          # XXX: could use some caching
> -        if not self.inbundle(rev):
> +        if rev not in self.basemap:
>              return revlog.revlog._chunk(self, rev)
>          self.bundle.seek(self.start(rev))
>          return self.bundle.read(self.length(rev))
>
>      def revdiff(self, rev1, rev2):
>          """return or calculate a delta between two revisions"""
> -        if self.inbundle(rev1) and self.inbundle(rev2):
> +        if rev1 in self.basemap and rev2 in self.basemap:
>              # hot path for bundle
>              revb = self.rev(self.basemap[rev2])
>              if revb == rev1:
>                  return self._chunk(rev2)
> -        elif not self.inbundle(rev1) and not self.inbundle(rev2):
> +        elif rev1 not in self.basemap and rev2 not in self.basemap:
>              return revlog.revlog.revdiff(self, rev1, rev2)
>
>          return mdiff.textdiff(self.revision(self.node(rev1)),
> @@ -116,7 +110,7 @@
>          chain = []
>          iter_node = node
>          # reconstruct the revision if it is from a changegroup
> -        while self.inbundle(rev):
> +        while rev in self.basemap:
>              if self._cache and self._cache[0] == iter_node:
>                  text = self._cache[2]
>                  break
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py
+++ b/mercurial/bundlerepo.py
@@ -70,29 +70,23 @@ 
             chain = node
             n += 1
 
-    def inbundle(self, rev):
-        """is rev from the bundle"""
-        if rev < 0:
-            return False
-        return rev in self.basemap
-
     def _chunk(self, rev):
         # Warning: in case of bundle, the diff is against self.basemap,
         # not against rev - 1
         # XXX: could use some caching
-        if not self.inbundle(rev):
+        if rev not in self.basemap:
             return revlog.revlog._chunk(self, rev)
         self.bundle.seek(self.start(rev))
         return self.bundle.read(self.length(rev))
 
     def revdiff(self, rev1, rev2):
         """return or calculate a delta between two revisions"""
-        if self.inbundle(rev1) and self.inbundle(rev2):
+        if rev1 in self.basemap and rev2 in self.basemap:
             # hot path for bundle
             revb = self.rev(self.basemap[rev2])
             if revb == rev1:
                 return self._chunk(rev2)
-        elif not self.inbundle(rev1) and not self.inbundle(rev2):
+        elif rev1 not in self.basemap and rev2 not in self.basemap:
             return revlog.revlog.revdiff(self, rev1, rev2)
 
         return mdiff.textdiff(self.revision(self.node(rev1)),
@@ -116,7 +110,7 @@ 
         chain = []
         iter_node = node
         # reconstruct the revision if it is from a changegroup
-        while self.inbundle(rev):
+        while rev in self.basemap:
             if self._cache and self._cache[0] == iter_node:
                 text = self._cache[2]
                 break