summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorZsolt Kozaroczy <[email protected]>2023-06-09 10:58:23 +0200
committerGitHub <[email protected]>2023-06-09 10:58:23 +0200
commitcfb516062de3d0725b3245cc328f96d702d662d3 (patch)
treeaac97180441376a9696b73e82f7b2f7d6ce19766
parentde23c1204a4999f747740cd119b0f74247b2f9d5 (diff)
parentb429bd3e7509eafa3f72fb918e691bb8dacc7b19 (diff)
downloadcaxlsx-cfb516062de3d0725b3245cc328f96d702d662d3.tar.gz
caxlsx-cfb516062de3d0725b3245cc328f96d702d662d3.zip
Merge pull request #278 from tagliala/chore/invert-nil-checks
Invert nil checks to improve performance
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb16
-rw-r--r--lib/axlsx/workbook/worksheet/cell_serializer.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/rich_text_run.rb2
3 files changed, 10 insertions, 10 deletions
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb
index 3146bca4..b9f78fdb 100644
--- a/lib/axlsx/workbook/worksheet/cell.rb
+++ b/lib/axlsx/workbook/worksheet/cell.rb
@@ -177,12 +177,12 @@ module Axlsx
# Indicates if the cell is good for shared string table
def plain_string?
- (type == :string || type == :text) && # String typed
- !is_text_run? && # No inline styles
- [email protected]? && # Not nil
- [email protected]? && # Not empty
- !is_formula? && # Not a formula
- !is_array_formula? # Not an array formula
+ (type == :string || type == :text) && # String typed
+ !value.nil? &&
+ !value.empty? &&
+ !is_text_run? && # No inline styles
+ !is_formula? &&
+ !is_array_formula?
end
# The inline font_name property for the cell
@@ -426,7 +426,7 @@ module Axlsx
# Attempts to determine the correct width for this cell's content
# @return [Float]
def autowidth
- return if is_formula? || value.nil?
+ return if value.nil? || is_formula?
if contains_rich_text?
string_width('', font_size) + value.autowidth
@@ -525,7 +525,7 @@ module Axlsx
# About Time - Time in OOXML is *different* from what you might expect. The history as to why is interesting, but you can safely assume that if you are generating docs on a mac, you will want to specify Workbook.1904 as true when using time typed values.
# @see Axlsx#date1904
def cast_value(v)
- return v if v.is_a?(RichText) || v.nil?
+ return v if v.nil? || v.is_a?(RichText)
case type
when :date
diff --git a/lib/axlsx/workbook/worksheet/cell_serializer.rb b/lib/axlsx/workbook/worksheet/cell_serializer.rb
index 30a2b5fe..9075c9c3 100644
--- a/lib/axlsx/workbook/worksheet/cell_serializer.rb
+++ b/lib/axlsx/workbook/worksheet/cell_serializer.rb
@@ -27,7 +27,7 @@ module Axlsx
if cell.is_text_run?
valid = RichTextRun::INLINE_STYLES - [:value, :type]
data = Axlsx.instance_values_for(cell).transform_keys(&:to_sym)
- data = data.select { |key, value| valid.include?(key) && !value.nil? }
+ data = data.select { |key, value| !value.nil? && valid.include?(key) }
RichText.new(cell.value.to_s, data).to_xml_string(str)
elsif cell.contains_rich_text?
cell.value.to_xml_string(str)
diff --git a/lib/axlsx/workbook/worksheet/rich_text_run.rb b/lib/axlsx/workbook/worksheet/rich_text_run.rb
index dac27752..02c350a7 100644
--- a/lib/axlsx/workbook/worksheet/rich_text_run.rb
+++ b/lib/axlsx/workbook/worksheet/rich_text_run.rb
@@ -208,7 +208,7 @@ module Axlsx
def to_xml_string(str = +'')
valid = RichTextRun::INLINE_STYLES
data = Axlsx.instance_values_for(self).transform_keys(&:to_sym)
- data = data.select { |key, value| valid.include?(key) && !value.nil? }
+ data = data.select { |key, value| !value.nil? && valid.include?(key) }
str << '<r><rPr>'
data.each do |key, val|