use multiplex regex to implement routing #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
multiplexing newark routing
The objectives of this PR are to make routing in Newark framework flexible and fast.
the advantages
/people/1.xmland enforce the xml extension, we will need to use a nerdy regex likeget \/people\/(?<id>\S*).xml$/ {...}. this change allows a much readable syntax such asget '/people/:id.xml/ {...}. It even allows syntax likeget '/people/:id.:format/ {...}(see the 2 new teststest/test_router.rb)N.B. the code can obviously be refactored, but I'd leave it for a future update.
Survey of routing algorithm in ruby web frameworks
many approaches are used in
our current approach that loop through all route's regex and match. some of the gems that use it include:
the disadvantage of this approach is its O(n) complexity, especially a large amount of routes are matched.
multiplexing approach. this approach takes advantage of the ruby regular expression's
unionandnamed capturefunctionality to create a multiplex route and match only once. It additionally benefits from the better performance of===overmatchmethod. it has O(1) complexity.Benchmark results
with mri ruby 2.1.1, on MacPro,