Skip to content

Commit 845f19a

Browse files
committed
Avoid dynamic constant get on SET.symbols
Dynamic constant lookups (ie. x::SOME_CONST) are uncommon and slightly slow operations (not _that_ slow). We know that the ::SET constant won't change (this is a private API and it is called only with our own classes) so we can switch this to an attr_reader for fast access on the call to delgate_to. This also removes the unused `type_klass` attr_accessor.
1 parent b623494 commit 845f19a

File tree

1 file changed

+4
-7
lines changed
  • actionview/lib/action_view/template

1 file changed

+4
-7
lines changed

actionview/lib/action_view/template/types.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,15 @@ def ==(type)
3838
end
3939

4040
class << self
41-
attr_accessor :type_klass
41+
attr_reader :symbols
4242

4343
def delegate_to(klass)
44-
self.type_klass = klass
44+
@symbols = klass::SET.symbols
45+
@type_klass = klass
4546
end
4647

4748
def [](type)
48-
type_klass[type]
49-
end
50-
51-
def symbols
52-
type_klass::SET.symbols
49+
@type_klass[type]
5350
end
5451
end
5552

0 commit comments

Comments
 (0)