From 263b259b276edd075b0abcd6aad0e923230c2d15 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 7 Dec 2018 02:22:20 +0100 Subject: Various speed optimizations --- src/metadata.cpp | 70 ++++++++++++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 37 deletions(-) (limited to 'src/metadata.cpp') diff --git a/src/metadata.cpp b/src/metadata.cpp index af8dc1fe..fac2ae6b 100644 --- a/src/metadata.cpp +++ b/src/metadata.cpp @@ -858,6 +858,8 @@ struct Identifier::Private { optional description_{}; optional uri_{}; + Private() = default; + Private(const std::string &codeIn, const PropertyMap &properties) : code_(codeIn) { setProperties(properties); @@ -874,10 +876,9 @@ void Identifier::Private::setProperties( const PropertyMap &properties) // throw(InvalidValueTypeException) { { - auto oIter = properties.find(AUTHORITY_KEY); - if (oIter != properties.end()) { - if (auto genVal = - dynamic_cast(oIter->second.get())) { + const auto pVal = properties.get(AUTHORITY_KEY); + if (pVal) { + if (auto genVal = dynamic_cast(pVal->get())) { if (genVal->type() == BoxedValue::Type::STRING) { authority_ = Citation(genVal->stringValue()); } else { @@ -886,7 +887,7 @@ void Identifier::Private::setProperties( } } else { if (auto citation = - dynamic_cast(oIter->second.get())) { + dynamic_cast(pVal->get())) { authority_ = *citation; } else { throw InvalidValueTypeException("Invalid value type for " + @@ -897,10 +898,9 @@ void Identifier::Private::setProperties( } { - auto oIter = properties.find(CODE_KEY); - if (oIter != properties.end()) { - if (auto genVal = - dynamic_cast(oIter->second.get())) { + const auto pVal = properties.get(CODE_KEY); + if (pVal) { + if (auto genVal = dynamic_cast(pVal->get())) { if (genVal->type() == BoxedValue::Type::INTEGER) { code_ = toString(genVal->integerValue()); } else if (genVal->type() == BoxedValue::Type::STRING) { @@ -916,45 +916,30 @@ void Identifier::Private::setProperties( } } - { - std::string temp; - if (properties.getStringValue(CODESPACE_KEY, temp)) { - codeSpace_ = temp; - } - } - - { - std::string temp; - if (properties.getStringValue(VERSION_KEY, temp)) { - version_ = temp; - } - } - - { - std::string temp; - if (properties.getStringValue(DESCRIPTION_KEY, temp)) { - description_ = temp; - } - } - - { - std::string temp; - if (properties.getStringValue(URI_KEY, temp)) { - uri_ = temp; - } - } + properties.getStringValue(CODESPACE_KEY, codeSpace_); + properties.getStringValue(VERSION_KEY, version_); + properties.getStringValue(DESCRIPTION_KEY, description_); + properties.getStringValue(URI_KEY, uri_); } //! @endcond // --------------------------------------------------------------------------- -Identifier::Identifier(const std::string &codeIn, const PropertyMap &properties) +Identifier::Identifier(const std::string &codeIn, + const util::PropertyMap &properties) : d(internal::make_unique(codeIn, properties)) {} // --------------------------------------------------------------------------- //! @cond Doxygen_Suppress + +// --------------------------------------------------------------------------- + +Identifier::Identifier() : d(internal::make_unique()) {} + +// --------------------------------------------------------------------------- + Identifier::Identifier(const Identifier &other) : d(internal::make_unique(*(other.d))) {} @@ -979,6 +964,17 @@ IdentifierNNPtr Identifier::create(const std::string &codeIn, // --------------------------------------------------------------------------- +//! @cond Doxygen_Suppress +IdentifierNNPtr +Identifier::createFromDescription(const std::string &descriptionIn) { + auto id = Identifier::nn_make_shared(); + id->d->description_ = descriptionIn; + return id; +} +//! @endcond + +// --------------------------------------------------------------------------- + /** \brief Return a citation for the organization responsible for definition and * maintenance of the code. * -- cgit v1.2.3