Skip to content

Commit 0588a46

Browse files
committed
Cache Journey Node#to_s
Even though the generation has been optimized, it is wasteful to keep generating the same string again and again. Initially I wasn't really for adding this cache, but Matthew pointed that the `uri_pattern` is accessed by Open Telemetry, so lazily memoizing seem sound.
1 parent f010edc commit 0588a46

File tree

1 file changed

+2
-1
lines changed
  • actionpack/lib/action_dispatch/journey/nodes

1 file changed

+2
-1
lines changed

actionpack/lib/action_dispatch/journey/nodes/node.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,15 @@ class Node # :nodoc:
7474
def initialize(left)
7575
@left = left
7676
@memo = nil
77+
@to_s = nil
7778
end
7879

7980
def each(&block)
8081
Visitors::Each::INSTANCE.accept(self, block)
8182
end
8283

8384
def to_s
84-
Visitors::String::INSTANCE.accept(self, "".dup)
85+
@to_s ||= Visitors::String::INSTANCE.accept(self, "".dup).freeze
8586
end
8687

8788
def to_dot

0 commit comments

Comments
 (0)