Mercurial > hgrepos > Python > libs > ConfigMix
comparison configmix/config.py @ 477:1de6cc49776e
Optimize .unquote() by aliasing some methods to locals and avoiding the first append call
| author | Franz Glasner <f.glasner@feldmann-mg.com> |
|---|---|
| date | Fri, 17 Dec 2021 11:42:47 +0100 |
| parents | eddc0f7c6271 |
| children | ff8a9a7c6a93 |
comparison
equal
deleted
inserted
replaced
| 476:eddc0f7c6271 | 477:1de6cc49776e |
|---|---|
| 734 This is the inverse of :meth:`~.quote`. | 734 This is the inverse of :meth:`~.quote`. |
| 735 | 735 |
| 736 """ | 736 """ |
| 737 if klass._QUOTE not in s: | 737 if klass._QUOTE not in s: |
| 738 return s | 738 return s |
| 739 res = [] | |
| 740 parts = s.split(klass._QUOTE) | 739 parts = s.split(klass._QUOTE) |
| 741 res.append(parts[0]) | 740 res = [parts[0]] |
| 741 res_append = res.append | |
| 742 for p in parts[1:]: | 742 for p in parts[1:]: |
| 743 if p.startswith(u(b'x')): | 743 if p.startswith(u(b'x')): |
| 744 if len(p) < 3: | 744 if len(p) < 3: |
| 745 raise ValueError("quote syntax: length too small") | 745 raise ValueError("quote syntax: length too small") |
| 746 res.append(uchr(int(p[1:3], 16))) | 746 res_append(uchr(int(p[1:3], 16))) |
| 747 res.append(p[3:]) | 747 res_append(p[3:]) |
| 748 elif p.startswith(u(b'u')): | 748 elif p.startswith(u(b'u')): |
| 749 if len(p) < 5: | 749 if len(p) < 5: |
| 750 raise ValueError("quote syntax: length too small") | 750 raise ValueError("quote syntax: length too small") |
| 751 res.append(uchr(int(p[1:5], 16))) | 751 res_append(uchr(int(p[1:5], 16))) |
| 752 res.append(p[5:]) | 752 res_append(p[5:]) |
| 753 elif p.startswith(u(b'U')): | 753 elif p.startswith(u(b'U')): |
| 754 if len(p) < 9: | 754 if len(p) < 9: |
| 755 raise ValueError("quote syntax: length too small") | 755 raise ValueError("quote syntax: length too small") |
| 756 res.append(uchr(int(p[1:9], 16))) | 756 res_append(uchr(int(p[1:9], 16))) |
| 757 res.append(p[9:]) | 757 res_append(p[9:]) |
| 758 else: | 758 else: |
| 759 raise ValueError("unknown quote syntax string: {}".format(s)) | 759 raise ValueError("unknown quote syntax string: {}".format(s)) |
| 760 return ''.join(res) | 760 return ''.join(res) |
| 761 | 761 |
| 762 def jailed(self, rootpath=None, root=None, bind_root=True): | 762 def jailed(self, rootpath=None, root=None, bind_root=True): |
