From ba7d1757f02663ce9231e08e0ccb6b45155f9204 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Fri, 8 Sep 2023 23:07:09 +0200 Subject: Use `class.name` instead of `class.to_s` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `class.name` is faster, uses less memory than `class.to_s`, and can be used in this context. This micro optimization does not have practical effect, it is just a reference for the future in case this approach will be needed in other parts of the library ``` Comparison (IPS): Object.name: 13528803.0 i/s Object.to_s: 8213612.0 i/s - 1.65x (± 0.00) slower Comparison (Memory): Object.name: 0 allocated Object.to_s: 40 allocated - Infx more ``` --- lib/axlsx/drawing/area_chart.rb | 2 +- lib/axlsx/drawing/line_chart.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/axlsx/drawing/area_chart.rb b/lib/axlsx/drawing/area_chart.rb index 8a01f9f5..1d26a8fc 100644 --- a/lib/axlsx/drawing/area_chart.rb +++ b/lib/axlsx/drawing/area_chart.rb @@ -63,7 +63,7 @@ module Axlsx # chart based on the actual class type and not a fixed node name. # @return [String] def node_name - path = self.class.to_s + path = self.class.name if i = path.rindex('::') path = path[(i + 2)..-1] end diff --git a/lib/axlsx/drawing/line_chart.rb b/lib/axlsx/drawing/line_chart.rb index 14577900..c922de78 100644 --- a/lib/axlsx/drawing/line_chart.rb +++ b/lib/axlsx/drawing/line_chart.rb @@ -63,7 +63,7 @@ module Axlsx # chart based on the actual class type and not a fixed node name. # @return [String] def node_name - path = self.class.to_s + path = self.class.name if i = path.rindex('::') path = path[(i + 2)..-1] end -- cgit v1.2.3