mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
memoize calls to xml::qname builder
This commit is contained in:
parent
53d7dbb67e
commit
85010f9f11
|
@ -58,9 +58,23 @@ struct hash<xml::qname>
|
|||
|
||||
namespace {
|
||||
|
||||
xml::qname qn(const std::string &namespace_, const std::string &name)
|
||||
xml::qname &qn(const std::string &namespace_, const std::string &name)
|
||||
{
|
||||
return xml::qname(xlnt::constants::ns(namespace_), name);
|
||||
static auto &memo = *new std::unordered_map<std::string, std::unordered_map<std::string, xml::qname>>();
|
||||
|
||||
if (!memo.count(namespace_))
|
||||
{
|
||||
memo[namespace_] = std::unordered_map<std::string, xml::qname>();
|
||||
}
|
||||
|
||||
auto &ns_memo = memo[namespace_];
|
||||
|
||||
if (!ns_memo.count(name))
|
||||
{
|
||||
ns_memo[name] = xml::qname(xlnt::constants::ns(namespace_), name);
|
||||
}
|
||||
|
||||
return ns_memo[name];
|
||||
}
|
||||
|
||||
#ifdef THROW_ON_INVALID_XML
|
||||
|
|
Loading…
Reference in New Issue
Block a user