Class: RuboCop::Cop::SketchupPerformance::Typename

Inherits:
SketchUp::Cop show all
Defined in:
lib/rubocop/sketchup/cop/performance/typename.rb

Overview

‘.typename` is very slow, prefer `.is_a?` instead.

‘entity.typename == ’Face’‘ is slow because it performs a string comparison. `is_a?` is much faster because it’s a simple type check.

Constant Summary collapse

MSG =
'`.typename` is very slow, prefer `.is_a?` instead.'

Constants inherited from SketchUp::Cop

SketchUp::Cop::SKETCHUP_DEPARTMENT_SEVERITY

Constants included from SketchUp::Config

SketchUp::Config::DEFAULT_CONFIGURATION

Instance Method Summary collapse

Methods inherited from SketchUp::Cop

inherited, #relevant_file?

Instance Method Details

#on_send(node) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/rubocop/sketchup/cop/performance/typename.rb', line 13

def on_send(node)
  _, method_name = *node
  return unless method_name == :typename

  # TODO(thomthom): Should we try to detect use of #typename
  # in context of comparing against a string?
  add_offense(node, location: :selector)
end