# HG changeset patch # User Franz Glasner # Date 1639919428 -3600 # Node ID 3387a9d5fb126f7b387f06a3cbf91e44ab512438 # Parent d803321d927bbb17cd9b7243291e340e62ad20bb Performance: compute the length of the constant input strinc only once and compute the new rest earlier and use the computed value also in comparisons diff -r d803321d927b -r 3387a9d5fb12 configmix/config.py --- a/configmix/config.py Sun Dec 19 14:05:14 2021 +0100 +++ b/configmix/config.py Sun Dec 19 14:10:28 2021 +0100 @@ -746,6 +746,7 @@ start = s.find(_STARTTOK, 0) if start < 0: return s + len_s = len(s) res = [] res_append = res.append rest = 0 @@ -773,11 +774,12 @@ UserWarning, stacklevel=1) raise + rest = end + 2 # # Dont apply and type conversions to the variable value if # the whole `s` is just one expansion # - if (start == 0) and (end + 2 == len(s)): + if (start == 0) and (rest == len_s): return varvalue if not varvalue: # None and/or empty str are handled equally here @@ -785,7 +787,6 @@ else: res_append(str_and_u(varvalue)) # don't re-evaluate because `self.getvar_s()` expands already - rest = end + 2 start = s.find(_STARTTOK, rest) res_append(s[rest:]) return _EMPTY_STR.join(res)