diff --git a/src/libexpr/names.cc b/src/libexpr/names.cc index c2b27333..cda5aa19 100644 --- a/src/libexpr/names.cc +++ b/src/libexpr/names.cc @@ -1,6 +1,5 @@ #include "names.hh" #include "util.hh" -#include "regex.hh" namespace nix { @@ -34,8 +33,8 @@ DrvName::DrvName(const string & s) : hits(0) bool DrvName::matches(DrvName & n) { if (name != "*") { - Regex regex(name); - if (!regex.matches(n.name)) return false; + if (!regex) regex = std::shared_ptr(new Regex(name)); + if (!regex->matches(n.name)) return false; } if (version != "" && version != n.version) return false; return true; diff --git a/src/libexpr/names.hh b/src/libexpr/names.hh index ebe113e8..4b3dcddf 100644 --- a/src/libexpr/names.hh +++ b/src/libexpr/names.hh @@ -1,6 +1,9 @@ #pragma once +#include + #include "types.hh" +#include "regex.hh" namespace nix { @@ -14,6 +17,9 @@ struct DrvName DrvName(); DrvName(const string & s); bool matches(DrvName & n); + +private: + std::shared_ptr regex; }; typedef list DrvNames;