-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize memory alloc and retained (#2441)
* Fix Cache in namespace and path Compile! skip non defined method Pattern, optimize capture_default Use delete_if instead of - * Revert root_prefix and to_regexp * Refactor path * Fix prefix, api string allocation * Drop AttributeTranslator in favor of OrderedOptions Manage Route regexp in Route class * Add cache for capture_index * Drop attribute_translator Remove useless alias * Fix all Rubocop Lint/MissingSuper Add changelog
- Loading branch information
1 parent
6fe78d1
commit 7c3ff27
Showing
22 changed files
with
129 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
module Grape | ||
class Router | ||
class BaseRoute | ||
delegate_missing_to :@options | ||
|
||
attr_reader :index, :pattern, :options | ||
|
||
def initialize(**options) | ||
@options = ActiveSupport::OrderedOptions.new.update(options) | ||
end | ||
|
||
alias attributes options | ||
|
||
def regexp_capture_index | ||
CaptureIndexCache[index] | ||
end | ||
|
||
def pattern_regexp | ||
pattern.to_regexp | ||
end | ||
|
||
def to_regexp(index) | ||
@index = index | ||
Regexp.new("(?<#{regexp_capture_index}>#{pattern_regexp})") | ||
end | ||
|
||
class CaptureIndexCache < Grape::Util::Cache | ||
def initialize | ||
super | ||
@cache = Hash.new do |h, index| | ||
h[index] = "_#{index}" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.