mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
use memoization to replace cached static qnames
This commit is contained in:
parent
85010f9f11
commit
bbdace8b44
|
@ -150,12 +150,6 @@ void xlsx_consumer::open(std::istream &source)
|
|||
populate_workbook(true);
|
||||
}
|
||||
|
||||
// caching frequently used names
|
||||
static const auto sheetData_el = qn("spreadsheetml", "sheetData");
|
||||
static const auto row_el = qn("spreadsheetml", "row");
|
||||
static const auto cell_el = qn("spreadsheetml", "c");
|
||||
static const auto val_el = qn("spreadsheetml", "v");
|
||||
|
||||
cell xlsx_consumer::read_cell()
|
||||
{
|
||||
if (!has_cell())
|
||||
|
@ -165,9 +159,9 @@ cell xlsx_consumer::read_cell()
|
|||
|
||||
auto ws = worksheet(current_worksheet_);
|
||||
|
||||
if (in_element(sheetData_el))
|
||||
if (in_element(qn("spreadsheetml", "sheetData")))
|
||||
{
|
||||
expect_start_element(row_el, xml::content::complex); // CT_Row
|
||||
expect_start_element(qn("spreadsheetml", "row"), xml::content::complex); // CT_Row
|
||||
auto row_index = static_cast<row_t>(std::stoul(parser().attribute("r")));
|
||||
|
||||
if (parser().attribute_present("ht"))
|
||||
|
@ -190,12 +184,12 @@ cell xlsx_consumer::read_cell()
|
|||
"ph", "spans" });
|
||||
}
|
||||
|
||||
if (!in_element(row_el))
|
||||
if (!in_element(qn("spreadsheetml", "row")))
|
||||
{
|
||||
return cell(nullptr);
|
||||
}
|
||||
|
||||
expect_start_element(cell_el, xml::content::complex);
|
||||
expect_start_element(qn("spreadsheetml", "c"), xml::content::complex);
|
||||
|
||||
auto cell = streaming_ ? xlnt::cell(streaming_cell_.get())
|
||||
: ws.cell(cell_reference(parser().attribute("r")));
|
||||
|
@ -217,11 +211,11 @@ cell xlsx_consumer::read_cell()
|
|||
auto has_shared_formula = false;
|
||||
auto formula_value_string = std::string();
|
||||
|
||||
while (in_element(cell_el))
|
||||
while (in_element(qn("spreadsheetml", "c")))
|
||||
{
|
||||
auto current_element = expect_start_element(xml::content::mixed);
|
||||
|
||||
if (current_element == val_el) // s:ST_Xstring
|
||||
if (current_element == qn("spreadsheetml", "v")) // s:ST_Xstring
|
||||
{
|
||||
has_value = true;
|
||||
value_string = read_text();
|
||||
|
@ -297,13 +291,13 @@ cell xlsx_consumer::read_cell()
|
|||
cell.format(target_.format(format_id));
|
||||
}
|
||||
|
||||
if (!in_element(row_el))
|
||||
if (!in_element(qn("spreadsheetml", "row")))
|
||||
{
|
||||
expect_end_element(row_el);
|
||||
expect_end_element(qn("spreadsheetml", "row"));
|
||||
|
||||
if (!in_element(sheetData_el))
|
||||
if (!in_element(qn("spreadsheetml", "sheetData")))
|
||||
{
|
||||
expect_end_element(sheetData_el);
|
||||
expect_end_element(qn("spreadsheetml", "sheetData"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1030,8 +1024,8 @@ xml::parser &xlsx_consumer::parser()
|
|||
|
||||
bool xlsx_consumer::has_cell()
|
||||
{
|
||||
return in_element(row_el)
|
||||
|| in_element(sheetData_el);
|
||||
return in_element(qn("spreadsheetml", "row"))
|
||||
|| in_element(qn("spreadsheetml", "sheetData"));
|
||||
}
|
||||
|
||||
std::vector<relationship> xlsx_consumer::read_relationships(const path &part)
|
||||
|
|
Loading…
Reference in New Issue
Block a user