summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorGeremia Taglialatela <[email protected]>2023-05-23 13:42:55 +0200
committerGeremia Taglialatela <[email protected]>2023-05-23 13:42:55 +0200
commit28b8b1a72affbab9ca81eb7629e9557adca372f1 (patch)
treec2d0e545c4e171b7633013162ff5a076e20bcf9c /lib
parent6752225bbb8a9eec905ec02a98f1a25a309c404a (diff)
downloadcaxlsx-28b8b1a72affbab9ca81eb7629e9557adca372f1.tar.gz
caxlsx-28b8b1a72affbab9ca81eb7629e9557adca372f1.zip
Improve cell type from value implementation
- Use `Regexp.match?` instead of `=~` when match is not needed - Use `Regexp.match` instead of `string.match` for uniformity ``` match?: 7335121.2 i/s =~: 2329358.3 i/s - 3.15x (± 0.00) slower ```
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb
index 49afa485..09cf2064 100644
--- a/lib/axlsx/workbook/worksheet/cell.rb
+++ b/lib/axlsx/workbook/worksheet/cell.rb
@@ -504,9 +504,9 @@ module Axlsx
:time
elsif v.is_a?(TrueClass) || v.is_a?(FalseClass)
:boolean
- elsif v.respond_to?(:to_i) && v.to_s =~ Axlsx::NUMERIC_REGEX
+ elsif v.respond_to?(:to_i) && Axlsx::NUMERIC_REGEX.match?(v.to_s)
:integer
- elsif v.respond_to?(:to_f) && (v.to_s =~ Axlsx::SAFE_FLOAT_REGEX || ((matchdata = v.to_s.match(MAYBE_FLOAT_REGEX)) && matchdata[:exp].to_i.between?(Float::MIN_10_EXP, Float::MAX_10_EXP)))
+ elsif v.respond_to?(:to_f) && (Axlsx::SAFE_FLOAT_REGEX.match?(v.to_s) || ((matchdata = MAYBE_FLOAT_REGEX.match(v.to_s)) && matchdata[:exp].to_i.between?(Float::MIN_10_EXP, Float::MAX_10_EXP)))
:float
elsif Axlsx::ISO_8601_REGEX.match?(v.to_s)
:iso_8601