mirror of
				https://gitea.invidious.io/iv-org/shard-kemal.git
				synced 2024-08-15 00:53:36 +00:00 
			
		
		
		
	Merge pull request #55 from luislavena/precompile-regex
Build Route Regex once to reduce allocations
This commit is contained in:
		
						commit
						2cc4c17c80
					
				
					 1 changed files with 2 additions and 1 deletions
				
			
		|  | @ -6,13 +6,14 @@ class Kemal::Route | |||
|   getter method | ||||
| 
 | ||||
|   def initialize(@method, @path, &@handler : Kemal::Context -> _) | ||||
|     @compiled_regex = pattern_to_regex(@path) | ||||
|   end | ||||
| 
 | ||||
|   def match?(request) | ||||
|     check_for_method_override!(request) | ||||
|     return nil unless request.override_method == @method | ||||
|     return true if request.path.not_nil!.includes?(':') && request.path.not_nil! == @path | ||||
|     request.path.not_nil!.match(pattern_to_regex(@path)) do |url_params| | ||||
|     request.path.not_nil!.match(@compiled_regex) do |url_params| | ||||
|       request.url_params = url_params | ||||
|       return true | ||||
|     end | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue