Mercurial > hgrepos > Python > libs > ConfigMix
changeset 515:3387a9d5fb12
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
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 19 Dec 2021 14:10:28 +0100 |
| parents | d803321d927b |
| children | ad1e630ba736 |
| files | configmix/config.py |
| diffstat | 1 files changed, 3 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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)
