I think you mean "alphabetical," or more specifically "in language
order" which is probably what you meant by "lexical."
I can see how an alphabetical list might work, but not completely.
Either way, I believe the end result is the same, which is the most
important thing for the docs -- the longest matching string will be
the one which is used -- but your way is more efficient.
I think what you're doing is searching the alphabetical list for where
you would find the request URI (even though the request URI is not
necessarily in the list). But, then you might have to backtrack up the
list until you find a matching path. For example, if the locations are
And the request is /n, then the initial search would return 1 -- e.g.,
in order to insert /n into the list, it would go after /a.
However, /a doesn't match /n so you would have to go back up the list
until you find /, which would match.
Maybe you found a way around this problem though. :)