comparison configmix/config.py @ 476:eddc0f7c6271

Optimize ._split_filters() for the most common case of no-filters: use s.partition() first
author Franz Glasner <f.glasner@feldmann-mg.com>
date Fri, 17 Dec 2021 11:09:14 +0100
parents fa5b800055e4
children 1de6cc49776e
comparison
equal deleted inserted replaced
475:fa5b800055e4 476:eddc0f7c6271
542 return (None, s, ) 542 return (None, s, )
543 else: 543 else:
544 return (self.unquote(nameparts[0]), nameparts[1], ) 544 return (self.unquote(nameparts[0]), nameparts[1], )
545 545
546 def _split_filters(self, s): 546 def _split_filters(self, s):
547 nameparts = s.split(self._FILTER_SEPARATOR) 547 try:
548 if len(nameparts) == 1: 548 name, sep, filters = s.partition(self._FILTER_SEPARATOR)
549 return (s, [], ) 549 if sep:
550 else: 550 filters = filters.strip()
551 return (nameparts[0].rstrip(), nameparts[1:], ) 551 if filters:
552 return (name.rstrip(),
553 filters.split(self._FILTER_SEPARATOR))
554 else:
555 return (name.rstrip(), [])
556 else:
557 return (name, [])
558 except AttributeError:
559 # pre PY 2.5
560 nameparts = s.split(self._FILTER_SEPARATOR)
561 if len(nameparts) == 1:
562 return (s, [], )
563 else:
564 return (nameparts[0].rstrip(), nameparts[1:], )
552 565
553 def _lookupvar(self, *path, **kwds): 566 def _lookupvar(self, *path, **kwds):
554 """Lookup a variable within a hierarchy. 567 """Lookup a variable within a hierarchy.
555 568
556 If no default is given an unexisting `path` raises a `KeyError` 569 If no default is given an unexisting `path` raises a `KeyError`