Skip to content

Commit 9d646bb

Browse files
committed
msg-filter: compile regexes statically
... to make the code easier to follow Related: https://issues.redhat.com/browse/OSH-663
1 parent 9c716e3 commit 9d646bb

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/lib/msg-filter.cc

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,6 @@ struct MsgFilter::Private {
6565
TMsgReplaceList repList;
6666
TSubstMap fileSubsts;
6767

68-
const std::string strKrn = "^[a-zA-Z+]+";
69-
const RE reKrn = RE(strKrn + /* convert el8_9 -> el8 */ "|_[0-9]+$");
70-
const RE reDir = RE("^([^:]*/)");
71-
const RE reFile = RE("[^/]+$");
72-
const RE rePath = RE("^(?:/builddir/build/BUILD/)?([^/]+)/(.*)(\\.[ly])?$");
73-
const RE rePyBuild = RE("^((?:/builddir/build/BUILD/)?[^/]+/)build/lib/(.*)$");
74-
const RE reTmpPath = RE("^(/var)?/tmp/(.*)$");
75-
const RE reTmpCleaner = RE("(.*)");
76-
7768
void addMsgFilter(
7869
const std::string &checker,
7970
const std::string &regexp,
@@ -247,47 +238,56 @@ std::string MsgFilter::filterPath(
247238
{
248239
std::string path = origPath;
249240

241+
static const RE reDir("^([^:]*/)");
242+
250243
TSubstMap &substMap = d->fileSubsts;
251244
if (!substMap.empty()) {
252-
std::string base = regexReplaceWrap(origPath, d->reDir, "");
253-
std::string dir = regexReplaceWrap(origPath, d->reFile, "");
245+
std::string base = regexReplaceWrap(origPath, reDir, "");
246+
static const RE reFile("[^/]+$");
247+
std::string dir = regexReplaceWrap(origPath, reFile, "");
254248
if (substMap.find(base) != substMap.end()) {
255249
const std::string &substWith = substMap[base];
256250
path = dir + substWith;
257251
}
258252
}
259253

260254
if (!forceFullPath && d->ignorePath)
261-
return regexReplaceWrap(path, d->reDir, "");
255+
return regexReplaceWrap(path, reDir, "");
262256

263-
if (boost::regex_match(path, d->reTmpPath)) {
257+
static const RE reTmpPath("^(/var)?/tmp/(.*)$");
258+
if (boost::regex_match(path, reTmpPath)) {
264259
// filter random numbers in names of temporary generated files
265-
std::string tmpPath = boost::regex_replace(path, d->reTmpCleaner, "/tmp/tmp.c");
260+
static const RE reTmpCleaner("(.*)");
261+
std::string tmpPath = boost::regex_replace(path, reTmpCleaner, "/tmp/tmp.c");
266262
return tmpPath;
267263
}
268264

269265
// "/usr/src/kernels/4.18.0-552.el8.x86_64+debug/..."
270266
// -> "/usr/src/kernels/VERSION-RELEASE+debug/..."
271-
const RE reKrnUsrSrc("^(/usr/src/kernels/)[^/-]+-[^/-]+((?:\\+debug)?/.*)$");
267+
static const RE reKrnUsrSrc("^(/usr/src/kernels/)[^/-]+-[^/-]+((?:\\+debug)?/.*)$");
272268
path = regexReplaceWrap(path, reKrnUsrSrc, "\\1VERSION-RELEASE\\2");
273269

274270
boost::smatch sm;
275-
if (boost::regex_match(path, sm, d->rePyBuild)) {
271+
static const RE rePyBuild("^((?:/builddir/build/BUILD/)?[^/]+/)build/lib/(.*)$");
272+
if (boost::regex_match(path, sm, rePyBuild)) {
276273
// %{_builddir}/build/lib/setuptools/glob.py ->
277274
// %{_builddir}/setuptools/glob.py
278275
path = sm[1] + sm[2];
279276
}
280277

281-
if (!boost::regex_match(path, sm, d->rePath))
278+
static const RE rePath("^(?:/builddir/build/BUILD/)?([^/]+)/(.*)(\\.[ly])?$");
279+
if (!boost::regex_match(path, sm, rePath))
282280
// no match
283281
return path;
284282

285283
const std::string nvr = sm[/* NVR */ 1];
286284
path = sm[/* core */ 2];
287285

288286
// try to kill the multiple version strings in paths (kernel, OpenLDAP, ...)
289-
const std::string ver = boost::regex_replace(nvr, d->reKrn, "");
290-
const std::string krnPattern = d->strKrn + ver + "[^/]*/";
287+
static const std::string strKrn = "^[a-zA-Z+]+";
288+
static const RE reKrn(strKrn + /* convert el8_9 -> el8 */ "|_[0-9]+$");
289+
const std::string ver = boost::regex_replace(nvr, reKrn, "");
290+
const std::string krnPattern = strKrn + ver + "[^/]*/";
291291

292292
#if DEBUG_SUBST > 2
293293
std::cerr << "nvr: " << nvr << "\n";

0 commit comments

Comments
 (0)