Skip to content

Commit baab208

Browse files
authored
Memoize regexp_capture_index reduces array allocation (#2642)
2 parents 2c3592e + 9d9bd0f commit baab208

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#### Fixes
1515

1616
* [#2633](https://github.com/ruby-grape/grape/pull/2633): Fix cascade reading - [@ericproulx](https://github.com/ericproulx).
17+
* [#2642](https://github.com/ruby-grape/grape/pull/2642): Fix array allocation in base_route.rb - [@ericproulx](https://github.com/ericproulx).
1718
* Your contribution here.
1819

1920
### 3.0.1 (2025-11-24)

lib/grape/router/base_route.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class BaseRoute
77

88
delegate_missing_to :@options
99

10-
attr_reader :index, :options, :pattern
10+
attr_reader :options, :pattern
1111

1212
def_delegators :@pattern, :path, :origin
1313
def_delegators :@options, :description, :version, :requirements, :prefix, :anchor, :settings, :forward_match, *Grape::Util::ApiDescription::DSL_METHODS
@@ -19,11 +19,11 @@ def initialize(pattern, options = {})
1919

2020
# see https://github.com/ruby-grape/grape/issues/1348
2121
def namespace
22-
@options[:namespace]
22+
@namespace ||= @options[:namespace]
2323
end
2424

2525
def regexp_capture_index
26-
CaptureIndexCache[index]
26+
@regexp_capture_index ||= CaptureIndexCache[@index]
2727
end
2828

2929
def pattern_regexp

0 commit comments

Comments
 (0)