Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/config.py @ 551:4c968c5cfce6
Try to interpolate only if the length of the source string exceeds a minimum length
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 02 Jan 2022 16:05:35 +0100 |
| parents | 79db28e879f8 |
| children | 39e5d07d8dbc |
comparison
equal
deleted
inserted
replaced
| 550:79db28e879f8 | 551:4c968c5cfce6 |
|---|---|
| 867 else: | 867 else: |
| 868 return obj | 868 return obj |
| 869 | 869 |
| 870 def interpolate_variables(self, s): | 870 def interpolate_variables(self, s): |
| 871 """Expand all variables in the single string `s`""" | 871 """Expand all variables in the single string `s`""" |
| 872 len_s = len(s) | |
| 873 if len_s < 4: | |
| 874 return s | |
| 872 start = s.find(_STARTTOK, 0) | 875 start = s.find(_STARTTOK, 0) |
| 873 if start < 0: | 876 if start < 0: |
| 874 return s | 877 return s |
| 875 res = self.__interpolation_cache.get(s, _MARKER) | 878 res = self.__interpolation_cache.get(s, _MARKER) |
| 876 if res is not _MARKER: | 879 if res is not _MARKER: |
| 881 stacklevel=1) | 884 stacklevel=1) |
| 882 raise KeyError("Cannot interpolate variables in string " | 885 raise KeyError("Cannot interpolate variables in string " |
| 883 "%r (cached)" % (s, )) | 886 "%r (cached)" % (s, )) |
| 884 else: | 887 else: |
| 885 return res | 888 return res |
| 886 len_s = len(s) | |
| 887 res = [] | 889 res = [] |
| 888 res_append = res.append | 890 res_append = res.append |
| 889 rest = 0 | 891 rest = 0 |
| 890 use_cache = True | 892 use_cache = True |
| 891 while start != -1: | 893 while start != -1: |
