Skip to content

Commit

Permalink
Avoid dynamic constant get on SET.symbols
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jhawthorn committed Jul 29, 2022
1 parent b623494 commit 845f19a
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions actionview/lib/action_view/template/types.rb
Expand Up @@ -38,18 +38,15 @@ def ==(type)
end

class << self
attr_accessor :type_klass
attr_reader :symbols

def delegate_to(klass)
self.type_klass = klass
@symbols = klass::SET.symbols
@type_klass = klass
end

def [](type)
type_klass[type]
end

def symbols
type_klass::SET.symbols
@type_klass[type]
end
end

Expand Down

0 comments on commit 845f19a

Please sign in to comment.