diff options
| -rw-r--r-- | lib/axlsx/stylesheet/color.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/workbook/shared_strings_table.rb | 17 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cell.rb | 11 | ||||
| -rw-r--r-- | test/profile.rb | 3 |
4 files changed, 19 insertions, 16 deletions
diff --git a/lib/axlsx/stylesheet/color.rb b/lib/axlsx/stylesheet/color.rb index 78171607..497e2d4d 100644 --- a/lib/axlsx/stylesheet/color.rb +++ b/lib/axlsx/stylesheet/color.rb @@ -72,5 +72,9 @@ module Axlsx str << "/>" end + def signature + "#{@rgb}:#{auto}:#{@tint}" + end + end end diff --git a/lib/axlsx/workbook/shared_strings_table.rb b/lib/axlsx/workbook/shared_strings_table.rb index 45402f5b..90aefced 100644 --- a/lib/axlsx/workbook/shared_strings_table.rb +++ b/lib/axlsx/workbook/shared_strings_table.rb @@ -30,8 +30,9 @@ module Axlsx # @param [Array] cells This is an array of all of the cells in the workbook def initialize(cells) cells = cells.flatten.reject { |c| c.type != :string || c.value.nil? || c.value.start_with?('=') } + @index = 0 @count = cells.size - @unique_cells = [] + @unique_cells = {} @shared_xml_string = "" resolve(cells) end @@ -53,15 +54,13 @@ module Axlsx def resolve(cells) cells.each do |cell| cell_hash = cell.shareable_hash - index = @unique_cells.index do |item| - item == cell_hash - end - if index == nil - cell.send :ssti=, @unique_cells.size - @shared_xml_string << '<si>' << cell.run_xml_string << '</si>' - @unique_cells << cell_hash - else + if index = @unique_cells[cell_hash] cell.send :ssti=, index + else + cell.send :ssti=, @index + @shared_xml_string << '<si>' << cell.run_xml_string << '</si>' + @unique_cells[cell_hash] = @index + @index += 1 end end end diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index f4c6ff09..262cab28 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -154,7 +154,7 @@ module Axlsx # @param [String] The 8 character representation for an rgb color #FFFFFFFF" def color=(v) @color = v.is_a?(Color) ? v : Color.new(:rgb=>v) - @has_run_style = true + @is_text_run = true end # The inline sz property for the cell @@ -203,6 +203,7 @@ module Axlsx # @option options [String] color an 8 letter rgb specification # @option options [Symbol] scheme must be one of :none, major, :minor def initialize(row, value="", options={}) + @signature = 0 self.row=row @font_name = @charset = @family = @b = @i = @strike = @outline = @shadow = nil @condense = @u = @vertAlign = @sz = @color = @scheme = @extend = @ssti = nil @@ -223,10 +224,7 @@ module Axlsx # equality comparison to test value, type and inline style attributes # this is how we work out if the cell needs to be added or already exists in the shared strings table def shareable_hash - self_hash = {} - INLINE_STYLES.each { |style| self_hash[style] = self.instance_variable_get("@" + style) } - self_hash['color'] = self_hash['color'].instance_values if self_hash['color'] - self_hash + "#{@signature} & #{@value} & #{@color && @color.signature}" end # @return [Integer] The index of the cell in the containing row. @@ -339,8 +337,9 @@ module Axlsx # Utility method for setting inline style attributes def set_run_style( validator, attr, value) - return unless INLINE_STYLES.include?(attr.to_s) + return unless idx = INLINE_STYLES.index(attr.to_s) Axlsx.send(validator, value) unless validator == nil + @signature += 2**idx self.instance_variable_set :"@#{attr.to_s}", value @is_text_run = true end diff --git a/test/profile.rb b/test/profile.rb index 97d2e2bc..fa81577b 100644 --- a/test/profile.rb +++ b/test/profile.rb @@ -15,11 +15,12 @@ require 'perftools' row = [] input = (32..126).to_a.pack('U*').chars.to_a 20.times { row << input.shuffle.join} -times = 1000 +times = 3000 PerfTools::CpuProfiler.start("/tmp/axlsx_noautowidth") do p = Axlsx::Package.new p.use_autowidth = false + p.use_shared_strings = true wb = p.workbook #A Simple Workbook |
