diff options
| author | Geremia Taglialatela <[email protected]> | 2023-09-08 23:07:09 +0200 |
|---|---|---|
| committer | Geremia Taglialatela <[email protected]> | 2023-09-08 23:07:09 +0200 |
| commit | ba7d1757f02663ce9231e08e0ccb6b45155f9204 (patch) | |
| tree | 118a1c272106b51fae7599adf02abcafa7fcb670 /lib | |
| parent | 3866257ec99c646a82c6f12e52361fbc4efc9b38 (diff) | |
| download | caxlsx-ba7d1757f02663ce9231e08e0ccb6b45155f9204.tar.gz caxlsx-ba7d1757f02663ce9231e08e0ccb6b45155f9204.zip | |
Use `class.name` instead of `class.to_s`
`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
```
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/drawing/area_chart.rb | 2 | ||||
| -rw-r--r-- | 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 |
