Make the inner-loop of path-matching a little less heavy.

Code's messier but this will be run on every request.