Migrate Warnings Provider from std::regex to RE2

This commit is contained in:
Dan Paulat 2023-12-10 21:59:32 -06:00
parent f612abb846
commit 2757c51828

View file

@ -3,7 +3,6 @@
#include <scwx/util/logger.hpp> #include <scwx/util/logger.hpp>
#include <ranges> #include <ranges>
#include <regex>
#include <shared_mutex> #include <shared_mutex>
#if defined(_MSC_VER) #if defined(_MSC_VER)
@ -13,6 +12,7 @@
#define LIBXML_HTML_ENABLED #define LIBXML_HTML_ENABLED
#include <cpr/cpr.h> #include <cpr/cpr.h>
#include <libxml/HTMLparser.h> #include <libxml/HTMLparser.h>
#include <re2/re2.h>
#if !defined(_MSC_VER) #if !defined(_MSC_VER)
# include <date/date.h> # include <date/date.h>
@ -77,7 +77,7 @@ WarningsProvider::ListFiles(std::chrono::system_clock::time_point newerThan)
using namespace date; using namespace date;
#endif #endif
static const std::regex reWarningsFilename { static constexpr LazyRE2 reWarningsFilename = {
"warnings_[0-9]{8}_[0-9]{2}.txt"}; "warnings_[0-9]{8}_[0-9]{2}.txt"};
static const std::string dateTimeFormat {"warnings_%Y%m%d_%H.txt"}; static const std::string dateTimeFormat {"warnings_%Y%m%d_%H.txt"};
@ -101,7 +101,7 @@ WarningsProvider::ListFiles(std::chrono::system_clock::time_point newerThan)
[](auto& record) [](auto& record)
{ {
return record.type_ == std::filesystem::file_type::regular && return record.type_ == std::filesystem::file_type::regular &&
std::regex_match(record.filename_, reWarningsFilename); RE2::FullMatch(record.filename_, *reWarningsFilename);
}); });
std::unique_lock lock(p->filesMutex_); std::unique_lock lock(p->filesMutex_);