Files
deb-python-falcon/tests
Kurt Griffiths f4b8b73c3d fix(falcon.routing.DefaultRouter): Do not mask variable path segments
When a single segment in a requested path can match more than one
node at that branch in the routing tree, and the first branch taken
happens to be the wrong one (i.e., the subsequent nodes do not match,
but they would have under a different branch), do not mask the other
branches that could result in a successful resolution of the requested
path.

I chose to implement this by not immediately returning None when a
branch prediction turns out to be false. Alternatively, I could have
introduced functions but that would likely incur more overhead vs.
performing a few additional node comparisons on the way back up the
routing tree. I did, however, include a simple optimization that
allows a "fast return" when only simple nodes are involved in the
branching, since in that case there is only one possible route.

More advanced optimizations are possible, and may be attempted in
the future. For example:

    * Graft the alternate branches directly into each point where the
      routing tree would otherwise 'return None'. This would balloon the
      size of the generated code, but would be akin to inline expansion
      of a routing representing the traversal of each branch where
      branch mispredictions are possible.
    * Introspect competing regular expressions to determine whether it
      is actually possible for them to match the same string given in
      the path.
    * Set a flag that can be referenced when returning from a branch
      misprediction in order to short-circuit checks. This may or may
      not be faster that some of the checks (i.e., those that check
      path length would not benefit from this flag, while those that
      index into the path list and perform a string comparison may be).
    * Rewrite the bytecode to allow direct jumps to alternate branches,
      ala https://github.com/snoack/python-goto

Fixes #702
2016-03-21 11:34:40 -05:00
..