[Epydoc-commits] SF.net SVN: epydoc: [1297] trunk/epydoc/src/epydoc/apidoc.py
Brought to you by:
edloper
From: <ed...@us...> - 2006-08-22 21:46:30
|
Revision: 1297 Author: edloper Date: 2006-08-22 14:46:27 -0700 (Tue, 22 Aug 2006) ViewCVS: http://svn.sourceforge.net/epydoc/?rev=1297&view=rev Log Message: ----------- - optimized DottedName.contextualize() and DottedName.dominates() for speed (based on patch provided by Daniel von Dincklage) Modified Paths: -------------- trunk/epydoc/src/epydoc/apidoc.py Modified: trunk/epydoc/src/epydoc/apidoc.py =================================================================== --- trunk/epydoc/src/epydoc/apidoc.py 2006-08-22 16:46:03 UTC (rev 1296) +++ trunk/epydoc/src/epydoc/apidoc.py 2006-08-22 21:46:27 UTC (rev 1297) @@ -192,9 +192,15 @@ >>> DottedName('a.b').dominates(DottedName('a.b.c.d')) True """ - if strict and len(self._identifiers)==len(name._identifiers): + len_self = len(self._identifiers) + len_name = len(name._identifiers) + + if (len_self > len_name) or (strict and len_self == len_name): return False - return self._identifiers == name._identifiers[:len(self)] + # The following is redundant (the first clause is implied by + # the second), but is done as an optimization. + return ((self._identifiers[0] == name._identifiers[0]) and + self._identifiers == name._identifiers[:len_self]) def contextualize(self, context): """ @@ -217,6 +223,22 @@ else: return self + # Find the first index where self & context differ. + for i in range(min(len(context), len(self))): + if self._identifiers[i] != context._identifiers[i]: + first_difference = i + break + else: + first_difference = i+1 + + # Strip off anything before that index. + if first_difference == 0: + return self + elif first_difference == len(self): + return self[-1:] + else: + return self[first_difference:] + ###################################################################### # UNKNOWN Value ###################################################################### This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |