From 956d0b5e06580b6465a67159a9c0d1dd719f6442 Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Fri, 9 Jun 2023 10:25:48 +0200 Subject: Refactor random char generation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix the following safe offenses: - Style/OperatorMethodCall - Style/RandomWithOffset And use Array.new to avoid an extra allocation: ``` Comparison (IPS): Array.new(8) { rand(65..89).chr }.join: 492433.7 i/s (0...8).map { 65.+(rand(25)).chr }.join: 432155.8 i/s - 1.14x (± 0.00) slower Comparison (Memory): Array.new(8) { rand(65..89).chr }.join: 440 allocated (0...8).map { 65.+(rand(25)).chr }.join: 560 allocated - 1.27x more ``` --- lib/axlsx/drawing/vml_shape.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/axlsx') diff --git a/lib/axlsx/drawing/vml_shape.rb b/lib/axlsx/drawing/vml_shape.rb index f1cd8951..4b21528f 100644 --- a/lib/axlsx/drawing/vml_shape.rb +++ b/lib/axlsx/drawing/vml_shape.rb @@ -24,7 +24,7 @@ module Axlsx @right_offset = 50 @bottom_offset = 5 @visible = true - @id = (0...8).map { 65.+(rand(25)).chr }.join + @id = Array.new(8) { rand(65..89).chr }.join parse_options options yield self if block_given? end -- cgit v1.2.3