Patchwork [1,of,3,STABLE] repoview: style change in newtype() cache handling

login
register
mail settings
Submitter Georges Racinet
Date April 26, 2021, 10:19 a.m.
Message ID <125fe190f484d396abc9.1619432381@purity.tombe.racinet.fr>
Download mbox | patch
Permalink /patch/48824/
State New
Headers show

Comments

Georges Racinet - April 26, 2021, 10:19 a.m.
# HG changeset patch
# User Georges Racinet <georges.racinet@octobus.net>
# Date 1619271999 -7200
#      Sat Apr 24 15:46:39 2021 +0200
# Branch stable
# Node ID 125fe190f484d396abc93428e3bd58b0b7455c24
# Parent  77e73827a02db25dc675b0afe552f24c807c741d
# EXP-Topic memleak-repo-class
repoview: style change in newtype() cache handling

This way of writing it does not change the logic at all,
but is more fit for the change we want to make in the
next changeset.

If anything, that's one dict lookup less in the hot path,
but that should be non measurable.
Raphaël Gomès - April 27, 2021, 8:40 a.m.
Queued the series, thanks!

On 4/26/21 12:19 PM, Georges Racinet wrote:
> # HG changeset patch
> # User Georges Racinet <georges.racinet@octobus.net>
> # Date 1619271999 -7200
> #      Sat Apr 24 15:46:39 2021 +0200
> # Branch stable
> # Node ID 125fe190f484d396abc93428e3bd58b0b7455c24
> # Parent  77e73827a02db25dc675b0afe552f24c807c741d
> # EXP-Topic memleak-repo-class
> repoview: style change in newtype() cache handling
>
> This way of writing it does not change the logic at all,
> but is more fit for the change we want to make in the
> next changeset.
>
> If anything, that's one dict lookup less in the hot path,
> but that should be non measurable.
>
> diff -r 77e73827a02d -r 125fe190f484 mercurial/repoview.py
> --- a/mercurial/repoview.py	Thu Apr 22 02:57:30 2021 +0200
> +++ b/mercurial/repoview.py	Sat Apr 24 15:46:39 2021 +0200
> @@ -472,10 +472,12 @@
>   
>   def newtype(base):
>       """Create a new type with the repoview mixin and the given base class"""
> -    if base not in _filteredrepotypes:
> +    cls = _filteredrepotypes.get(base)
> +    if cls is not None:
> +        return cls
>   
> -        class filteredrepo(repoview, base):
> -            pass
> +    class filteredrepo(repoview, base):
> +        pass
>   
> -        _filteredrepotypes[base] = filteredrepo
> -    return _filteredrepotypes[base]
> +    _filteredrepotypes[base] = filteredrepo
> +    return filteredrepo
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff -r 77e73827a02d -r 125fe190f484 mercurial/repoview.py
--- a/mercurial/repoview.py	Thu Apr 22 02:57:30 2021 +0200
+++ b/mercurial/repoview.py	Sat Apr 24 15:46:39 2021 +0200
@@ -472,10 +472,12 @@ 
 
 def newtype(base):
     """Create a new type with the repoview mixin and the given base class"""
-    if base not in _filteredrepotypes:
+    cls = _filteredrepotypes.get(base)
+    if cls is not None:
+        return cls
 
-        class filteredrepo(repoview, base):
-            pass
+    class filteredrepo(repoview, base):
+        pass
 
-        _filteredrepotypes[base] = filteredrepo
-    return _filteredrepotypes[base]
+    _filteredrepotypes[base] = filteredrepo
+    return filteredrepo