Mercurial > hgrepos > Python > libs > ConfigMix
changeset 479:490f0c4665bb
Optimize .unquote(): instead of doing string comparisone do this with characters
| author | Franz Glasner <f.glasner@feldmann-mg.com> |
|---|---|
| date | Fri, 17 Dec 2021 11:52:56 +0100 |
| parents | ff8a9a7c6a93 |
| children | 3cfc808e613b |
| files | configmix/config.py |
| diffstat | 1 files changed, 7 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/configmix/config.py Fri Dec 17 11:46:36 2021 +0100 +++ b/configmix/config.py Fri Dec 17 11:52:56 2021 +0100 @@ -743,17 +743,21 @@ res = [parts[0]] res_append = res.append for p in parts[1:]: - if p.startswith(klass._QUOTE_x): + try: + qc = p[0] + except IndexError: + raise ValueError("unknown quote syntax string: {}".format(s)) + if qc == klass._QUOTE_x: if len(p) < 3: raise ValueError("quote syntax: length too small") res_append(uchr(int(p[1:3], 16))) res_append(p[3:]) - elif p.startswith(klass._QUOTE_u): + elif qc == klass._QUOTE_u: if len(p) < 5: raise ValueError("quote syntax: length too small") res_append(uchr(int(p[1:5], 16))) res_append(p[5:]) - elif p.startswith(klass._QUOTE_U): + elif qc == klass._QUOTE_U: if len(p) < 9: raise ValueError("quote syntax: length too small") res_append(uchr(int(p[1:9], 16)))
