changeset 511:93a5346907ef

Using generator expressions to directly create tuples is a not so good idea performance-wise. Use it only if you have memory issues because it is not very performant. Using tuple([list comprenension]) is at most twice as fast.
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 18 Dec 2021 18:44:21 +0100
parents acf1e8696d68
children bf8a1b1498db
files configmix/config.py
diffstat 1 files changed, 12 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/configmix/config.py	Sat Dec 18 18:41:11 2021 +0100
+++ b/configmix/config.py	Sat Dec 18 18:44:21 2021 +0100
@@ -486,8 +486,8 @@
         varns, varname = self._split_ns(varname)
         if not varns:
             if varname:
-                varnameparts = (unquote(vp)
-                                for vp in varname.split(_HIER_SEPARATOR))
+                varnameparts = tuple([unquote(vp)
+                                      for vp in varname.split(_HIER_SEPARATOR)])
             else:
                 varnameparts = tuple()
         else:
@@ -837,7 +837,8 @@
                 raise ValueError(
                     "jailed configurations do not support namespaces")
             if varname:
-                rootpath = (unquote(p) for p in root.split(_HIER_SEPARATOR))
+                rootpath = tuple([unquote(p)
+                                  for p in root.split(_HIER_SEPARATOR)])
             else:
                 rootpath = tuple()
         jc = _JailedConfiguration(*rootpath)
@@ -1002,16 +1003,16 @@
 
     def getvar(self, varname, **kwds):
         if varname:
-            varnameparts = tuple(unquote(vp)
-                                 for vp in varname.split(_HIER_SEPARATOR))
+            varnameparts = tuple([unquote(vp)
+                                  for vp in varname.split(_HIER_SEPARATOR)])
         else:
             varnameparts = tuple()
         return self._base.getvarl(*(self._path + varnameparts), **kwds)
 
     def getkeys(self, varname):
         if varname:
-            varnameparts = tuple(unquote(vp)
-                                 for vp in varname.split(_HIER_SEPARATOR))
+            varnameparts = tuple([unquote(vp)
+                                  for vp in varname.split(_HIER_SEPARATOR)])
         else:
             varnameparts = tuple()
         for k in self._base.getkeysl(*(self._path + varnameparts)):
@@ -1023,8 +1024,8 @@
 
     def getvar_s(self, varname, **kwds):
         if varname:
-            varnameparts = tuple(unquote(vp)
-                                 for vp in varname.split(_HIER_SEPARATOR))
+            varnameparts = tuple([unquote(vp)
+                                  for vp in varname.split(_HIER_SEPARATOR)])
         else:
             varnameparts = tuple()
         return self._base.getvarl_s(*(self._path + varnameparts), **kwds)
@@ -1073,9 +1074,8 @@
                 raise ValueError(
                     "sub-jails do not support namespaces")
             if varname:
-                rootpath = (
-                    unquote(p) for p in varname.split(_HIER_SEPARATOR)
-                )
+                rootpath = tuple([unquote(p)
+                                  for p in varname.split(_HIER_SEPARATOR)])
             else:
                 rootpath = tuple()
         if self._path: