diff genshi/path.py @ 687:3d7288f373bd experimental-match-fastpaths

land first cut at fast-path matching - needs some cleanup
author aflett
date Mon, 25 Feb 2008 20:44:04 +0000
parents 1f73e534e715
children 919809e55d16
line wrap: on
line diff
--- a/genshi/path.py
+++ b/genshi/path.py
@@ -181,9 +181,15 @@
                  stream against the path
         :rtype: ``function``
         """
-        paths = [(p, len(p), [0], [], [0] * len(p)) for p in [
-            (ignore_context and [_DOTSLASHSLASH] or []) + p for p in self.paths
-        ]]
+
+        # paths is path state that is maintained across calls to _test()
+        # paths is a list of tuples, one for each segment in the path
+        paths = []
+        for p in self.paths:
+            if ignore_context:
+                p = [_DOTSLASHSLASH] + p
+            path = (p, len(p), [0], [], [0] * len(p))
+            paths.append(path)
 
         def _test(event, namespaces, variables, updateonly=False):
             kind, data, pos = event[:3]
@@ -279,7 +285,8 @@
                     if ctxtnode and axis is DESCENDANT_OR_SELF:
                         ctxtnode = False
 
-                if (retval or not matched) and kind is START and \
+                if (retval or not matched) and \
+                        kind is START and \
                         not (axis is DESCENDANT or axis is DESCENDANT_OR_SELF):
                     # If this step is not a closure, it cannot be matched until
                     # the current element is closed... so we need to move the
Copyright (C) 2012-2017 Edgewall Software