Fix for performance issue
This commit replace the regex usage with simple string operations decreasing
significantly the CPU load.
Tested:
Manual testes where made to the splitFileName function behavior and CPU
load. No regression detected.
Signed-off-by: Zbigniew Kurzynski <zbigniew.kurzynski@intel.com>
Change-Id: Ifacbe7c7daf7a90671d543b7cfd65cc571f7ce4b
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 1add0e6..f11a520 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -351,16 +351,17 @@
if (filePath.has_filename())
{
const auto fileName = filePath.filename().string();
- const std::regex rx(R"((\w+)(\d+)_(.*))");
- std::smatch mr;
- if (std::regex_search(fileName, mr, rx))
+ size_t numberPos = std::strcspn(fileName.c_str(), "1234567890");
+ size_t itemPos = std::strcspn(fileName.c_str(), "_");
+
+ if (numberPos > 0 && itemPos > numberPos && fileName.size() > itemPos)
{
- if (mr.size() == 4)
- {
- return std::make_optional(std::make_tuple(mr[1], mr[2], mr[3]));
- }
+ return std::make_optional(
+ std::make_tuple(fileName.substr(0, numberPos),
+ fileName.substr(numberPos, itemPos - numberPos),
+ fileName.substr(itemPos + 1, fileName.size())));
}
}
return std::nullopt;
-}
\ No newline at end of file
+}