diff configmix/config.py @ 603:e55a42144ba9

C-implementations for Configuration.getvarl() and Configuration.getvar_s()
author Franz Glasner <fzglas.hg@dom66.de>
date Tue, 11 Jan 2022 02:50:17 +0100
parents f454889e41fa
children 764d4185c76a
line wrap: on
line diff
--- a/configmix/config.py	Tue Jan 11 00:52:56 2022 +0100
+++ b/configmix/config.py	Tue Jan 11 02:50:17 2022 +0100
@@ -33,14 +33,17 @@
 try:
     from ._speedups import (fast_unquote, fast_quote, fast_pathstr2path,
                             _fast_split_ns, _fast_split_filters,
+                            _fast_getvarl, _fast_getvar_s,
                             _fast_interpolate_variables,
-                            _sync_MISSING)
+                            _sync_MISSING, _sync_MARKER)
 except ImportError:
     fast_unquote = None
     fast_quote = None
     fast_pathstr2path = None
     _fast_split_ns = None
     _fast_split_filters = None
+    _fast_getvarl = None
+    _fast_getvar_s = None
     _fast_interpolate_variables = None
     _sync_MISSING = None
 
@@ -503,7 +506,7 @@
         for k in self:
             yield self.getitem_ns(k)
 
-    def getvarl(self, *path, **kwds):
+    def py_getvarl(self, *path, **kwds):
         """Get a variable where the hierarchy is given in `path` as sequence
         and the namespace is given in the `namespace` keyword argument.
 
@@ -531,6 +534,16 @@
         else:
             return varvalue
 
+    if _fast_getvarl:
+
+        def fast_getvarl(self, *args, **kwds):
+            return _fast_getvarl(self, args, **kwds)
+
+        getvarl = fast_getvarl
+
+    else:
+        getvarl = py_getvarl
+
     def getkeysl(self, *path, **kwds):
         """Yield the keys of a variable value.
 
@@ -709,7 +722,7 @@
         else:
             return default
 
-    def getvar_s(self, varname, default=_MARKER):
+    def py_getvar_s(self, varname, default=_MARKER):
         """Get a variable - including variables from other namespaces.
 
         `varname` is interpreted as in :meth:`.getvar`. But variables
@@ -733,7 +746,18 @@
             else:
                 return default
 
-    def _getvar_s_with_cache_info(self, varname):
+    if _fast_getvar_s:
+
+        def fast_getvar_s(self, varname, default=_MARKER):
+            return _fast_getvar_s(self, varname, default)
+
+        getvar_s = fast_getvar_s
+
+    else:
+
+        getvar_s = py_getvar_s
+
+    def _py_getvar_s_with_cache_info(self, varname):
         """Internal variant of :meth:`~.getvar_s` that returns some information
         whether caching of interpolated values is allowed
 
@@ -909,7 +933,7 @@
             varname, filters = _split_filters(
                 s[start+2:end])     # noqa: E226
             try:
-                varvalue, cacheable = self._getvar_s_with_cache_info(varname)
+                varvalue, cacheable = self._py_getvar_s_with_cache_info(varname)
             except KeyError:
                 cacheable = True
                 if NONE_FILTER in filters:
@@ -1241,3 +1265,4 @@
 
 if _sync_MISSING:
     _sync_MISSING(_MISSING)
+    _sync_MARKER(_MARKER)