Skip to content

Commit 9d9bd0f

Browse files
committed
Memoize regexp_capture_index reduces array allocation
1 parent ea7bbb7 commit 9d9bd0f

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
@@ -12,6 +12,7 @@
1212
#### Fixes
1313

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

1718
### 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)