aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-09-21 18:22:45 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-09-21 18:22:45 +0200
commite8e1d420f364afbfface61d3f03889e10e6066c9 (patch)
tree2cd1a7637d516eb5d50501a5508231d979096cf7 /src/libstore
parentcbe0bb29f4531b2cd6b18775018bf030b1a909e3 (diff)
Don't include <regex> in header files
This reduces compilation time by ~15 seconds (CPU time). Issue #4045.
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/names.cc21
-rw-r--r--src/libstore/names.hh7
2 files changed, 23 insertions, 5 deletions
diff --git a/src/libstore/names.cc b/src/libstore/names.cc
index d1c8a6101..41e28dc99 100644
--- a/src/libstore/names.cc
+++ b/src/libstore/names.cc
@@ -1,10 +1,18 @@
#include "names.hh"
#include "util.hh"
+#include <regex>
+
namespace nix {
+struct Regex
+{
+ std::regex regex;
+};
+
+
DrvName::DrvName()
{
name = "";
@@ -30,11 +38,18 @@ DrvName::DrvName(std::string_view s) : hits(0)
}
+DrvName::~DrvName()
+{ }
+
+
bool DrvName::matches(DrvName & n)
{
if (name != "*") {
- if (!regex) regex = std::unique_ptr<std::regex>(new std::regex(name, std::regex::extended));
- if (!std::regex_match(n.name, *regex)) return false;
+ if (!regex) {
+ regex = std::make_unique<Regex>();
+ regex->regex = std::regex(name, std::regex::extended);
+ }
+ if (!std::regex_match(n.name, regex->regex)) return false;
}
if (version != "" && version != n.version) return false;
return true;
@@ -99,7 +114,7 @@ DrvNames drvNamesFromArgs(const Strings & opArgs)
{
DrvNames result;
for (auto & i : opArgs)
- result.push_back(DrvName(i));
+ result.emplace_back(i);
return result;
}
diff --git a/src/libstore/names.hh b/src/libstore/names.hh
index 00e14b8c7..bc62aac93 100644
--- a/src/libstore/names.hh
+++ b/src/libstore/names.hh
@@ -3,10 +3,11 @@
#include <memory>
#include "types.hh"
-#include <regex>
namespace nix {
+struct Regex;
+
struct DrvName
{
string fullName;
@@ -16,10 +17,12 @@ struct DrvName
DrvName();
DrvName(std::string_view s);
+ ~DrvName();
+
bool matches(DrvName & n);
private:
- std::unique_ptr<std::regex> regex;
+ std::unique_ptr<Regex> regex;
};
typedef list<DrvName> DrvNames;