From c418c13010a82010ef637174827e5fa9aef7dd1a Mon Sep 17 00:00:00 2001 From: JCrawfy Date: Sun, 1 Mar 2020 23:18:13 +1300 Subject: [PATCH] remove a double lookup in the cell map during serialisation --- source/cell/cell.cpp | 2 +- source/detail/implementations/cell_impl.hpp | 7 ++++++- source/detail/serialization/xlsx_producer.cpp | 17 ++++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/source/cell/cell.cpp b/source/cell/cell.cpp index ef6e7b24..e47f2a93 100644 --- a/source/cell/cell.cpp +++ b/source/cell/cell.cpp @@ -199,7 +199,7 @@ cell::cell(detail::cell_impl *d) bool cell::garbage_collectible() const { - return !(has_value() || is_merged() || phonetics_visible() || has_formula() || has_format() || has_hyperlink()); + return d_->is_garbage_collectible(); } void cell::value(std::nullptr_t) diff --git a/source/detail/implementations/cell_impl.hpp b/source/detail/implementations/cell_impl.hpp index 52e59444..11097414 100644 --- a/source/detail/implementations/cell_impl.hpp +++ b/source/detail/implementations/cell_impl.hpp @@ -47,7 +47,7 @@ struct cell_impl cell_impl(cell_impl &&other) = default; cell_impl &operator=(const cell_impl &other) = default; cell_impl &operator=(cell_impl &&other) = default; - + cell_type type_; worksheet_impl *parent_; @@ -65,6 +65,11 @@ struct cell_impl optional hyperlink_; optional format_; optional comment_; + + bool is_garbage_collectible() const + { + return !(type_ != cell_type::empty || is_merged_ || phonetics_visible_ || formula_.is_set() || format_.is_set() || hyperlink_.is_set()); + } }; inline bool operator==(const cell_impl &lhs, const cell_impl &rhs) diff --git a/source/detail/serialization/xlsx_producer.cpp b/source/detail/serialization/xlsx_producer.cpp index a0455cef..1646b70b 100644 --- a/source/detail/serialization/xlsx_producer.cpp +++ b/source/detail/serialization/xlsx_producer.cpp @@ -2483,12 +2483,19 @@ void xlsx_producer::write_worksheet(const relationship &rel) { for (auto column = dimension.top_left().column(); column <= dimension.bottom_right().column(); ++column) { - if (!ws.has_cell(cell_reference(column, check_row))) continue; - auto cell = ws.cell(cell_reference(column, check_row)); - if (cell.garbage_collectible()) continue; + auto ref = cell_reference(column, check_row); + auto cell = ws.d_->cell_map_.find(ref); + if (cell == ws.d_->cell_map_.end()) + { + continue; + } + if (cell->second.is_garbage_collectible()) + { + continue; + } - first_block_column = std::min(first_block_column, cell.column()); - last_block_column = std::max(last_block_column, cell.column()); + first_block_column = std::min(first_block_column, cell->second.column_); + last_block_column = std::max(last_block_column, cell->second.column_); if (row == check_row) {