Skip to content

Commit

Permalink
remove some regex to avoid slowdown
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <rosenp@gmail.com>
(cherry picked from commit 3f08319)
  • Loading branch information
neheb authored and kmilos committed Nov 27, 2023
1 parent 1639083 commit 3076cc6
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/datasets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include <array>
#include <iomanip>
#include <regex>
#include <sstream>

// *****************************************************************************
Expand Down Expand Up @@ -552,15 +551,14 @@ IptcKey* IptcKey::clone_() const {

void IptcKey::decomposeKey() {
// Check that the key has the expected format with RE
static const std::regex re(R"((\w+)(\.\w+){2})");
if (std::smatch sm; !std::regex_match(key_, sm, re)) {
auto posDot1 = key_.find('.');
auto posDot2 = key_.find('.', posDot1 + 1);

if (posDot1 == std::string::npos || posDot2 == std::string::npos) {
throw Error(ErrorCode::kerInvalidKey, key_);
}

// Get the family name, record name and dataSet name parts of the key
auto posDot1 = key_.find('.');
auto posDot2 = key_.find('.', posDot1 + 1);

const std::string familyName = key_.substr(0, posDot1);
if (familyName != familyName_)
throw Error(ErrorCode::kerInvalidKey, key_);
Expand Down

0 comments on commit 3076cc6

Please sign in to comment.