summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/worksheet/cell_serializer.rb
diff options
context:
space:
mode:
authorPaul Kmiec <[email protected]>2023-05-13 14:21:21 -0700
committerPaul Kmiec <[email protected]>2023-05-15 13:49:21 -0700
commit4627bcce04ade9c17e1d0c169100a6288195f6ac (patch)
tree7862f4a19e3bca9f6994dca882d5ce92cc3dbf46 /lib/axlsx/workbook/worksheet/cell_serializer.rb
parent3b9ac17d8e4dc8b315ac307ffad6f2aa0cb96741 (diff)
downloadcaxlsx-4627bcce04ade9c17e1d0c169100a6288195f6ac.tar.gz
caxlsx-4627bcce04ade9c17e1d0c169100a6288195f6ac.zip
Cache col_ref to avoid allocations
In cases with lots of rows, each column will ask for its col_ref which will always be the same for the same column_index. We can cache this to avoid lots of small string allocations. Modified `CellSerializer` to use `#col_ref` and `#row_ref` avoiding the string allocation caused by `#col_r`
Diffstat (limited to 'lib/axlsx/workbook/worksheet/cell_serializer.rb')
-rw-r--r--lib/axlsx/workbook/worksheet/cell_serializer.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/axlsx/workbook/worksheet/cell_serializer.rb b/lib/axlsx/workbook/worksheet/cell_serializer.rb
index e1bdf728..2baa4271 100644
--- a/lib/axlsx/workbook/worksheet/cell_serializer.rb
+++ b/lib/axlsx/workbook/worksheet/cell_serializer.rb
@@ -10,7 +10,9 @@ module Axlsx
# @param [String] str The string to apend serialization to.
# @return [String]
def to_xml_string(row_index, column_index, cell, str = +'')
- str << '<c r="' << Axlsx::cell_r(column_index, row_index) << '" s="' << cell.style.to_s << '" '
+ str << '<c r="'
+ str << Axlsx::col_ref(column_index) << Axlsx::row_ref(row_index)
+ str << '" s="' << cell.style.to_s << '" '
return str << '/>' if cell.value.nil?
method = cell.type