Skip to content

Commit 7520fc6

Browse files
authored
fix static regEX
1 parent c11aacf commit 7520fc6

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

library/src/include/option_util.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@
3535
#include <vector>
3636

3737
// Regular expression for token delimiters (whitespace and commas)
38-
static const std::regex program_options_regex{"[, \\f\\n\\r\\t\\v]+",
39-
std::regex_constants::optimize};
40-
41-
static const std::regex vector_delim{",", std::regex_constants::optimize};
38+
#define PROGRAM_OPTIONS_REGEX "[, \\f\\n\\r\\t\\v]+"
39+
#define VECTOR_DELIM ","
4240

4341
// variables_map is a set of seen options
4442
using variables_map = std::set<std::string>;
@@ -264,6 +262,9 @@ class options_description
264262
// Parse an option at the current (argc, argv) position
265263
void parse_option(int& argc, char**& argv, variables_map& vm, bool ignoreUnknown = false) const
266264
{
265+
static const std::regex program_options_regex{PROGRAM_OPTIONS_REGEX,
266+
std::regex_constants::optimize};
267+
267268
// Iterate across all options
268269
for(const auto& opt : m_optlist)
269270
{
@@ -312,6 +313,9 @@ class options_description
312313
// Formatted output of command-line arguments description
313314
friend std::ostream& operator<<(std::ostream& os, const options_description& d)
314315
{
316+
static const std::regex program_options_regex{PROGRAM_OPTIONS_REGEX,
317+
std::regex_constants::optimize};
318+
315319
// Iterate across all options
316320
for(const auto& opt : d.m_optlist)
317321
{
@@ -404,6 +408,8 @@ inline void notify(const variables_map&) {}
404408

405409
void parse_arg_ints(std::string const& inStr, std::vector<size_t>& outVector)
406410
{
411+
static const std::regex vector_delim{VECTOR_DELIM, std::regex_constants::optimize};
412+
407413
// std::cout << inStr << std::endl;
408414
for(std::sregex_token_iterator tok{inStr.begin(), inStr.end(), vector_delim, -1};
409415
tok != std::sregex_token_iterator();
@@ -415,6 +421,8 @@ void parse_arg_ints(std::string const& inStr, std::vector<size_t>& outVector)
415421

416422
void parse_arg_strings(std::string const& inStr, std::vector<std::string>& outVector)
417423
{
424+
static const std::regex vector_delim{VECTOR_DELIM, std::regex_constants::optimize};
425+
418426
// std::cout << inStr << std::endl;
419427
for(std::sregex_token_iterator tok{inStr.begin(), inStr.end(), vector_delim, -1};
420428
tok != std::sregex_token_iterator();

library/src/solution_map.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
namespace fs = std::filesystem;
3333

34-
static std::regex regEx("[^:;,\"\\{\\}\\[\\s]+", std::regex_constants::optimize);
34+
#define REGEX "[^:;,\"\\{\\}\\[\\s]+"
3535

3636
static const char* def_solution_map_path = "rocfft_solution_map.dat";
3737

@@ -477,6 +477,8 @@ size_t solution_map::add_solution(const ProblemKey& probKey,
477477
// parse the format version of the input file, call by converter
478478
bool solution_map::get_solution_map_version(const fs::path& sol_map_in_path)
479479
{
480+
static std::regex regEx(REGEX, std::regex_constants::optimize);
481+
480482
if(LOG_TRACE_ENABLED())
481483
(*LogSingleton::GetInstance().GetTraceOS())
482484
<< "reading solution map data from: " << sol_map_in_path.c_str() << std::endl;
@@ -505,6 +507,8 @@ bool solution_map::get_solution_map_version(const fs::path& sol_map_in_path)
505507
// read the map from input stream
506508
bool solution_map::read_solution_map_data(const fs::path& sol_map_in_path, bool primary_map)
507509
{
510+
static std::regex regEx(REGEX, std::regex_constants::optimize);
511+
508512
if(LOG_TRACE_ENABLED())
509513
(*LogSingleton::GetInstance().GetTraceOS())
510514
<< "reading solution map data from: " << sol_map_in_path.c_str() << std::endl;

0 commit comments

Comments
 (0)