forked from lix-project/lix
Don't recompile the same regex over and over
This commit is contained in:
parent
104e55bb7f
commit
3b5fa8d50c
|
@ -1,6 +1,5 @@
|
||||||
#include "names.hh"
|
#include "names.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
#include "regex.hh"
|
|
||||||
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
@ -34,8 +33,8 @@ DrvName::DrvName(const string & s) : hits(0)
|
||||||
bool DrvName::matches(DrvName & n)
|
bool DrvName::matches(DrvName & n)
|
||||||
{
|
{
|
||||||
if (name != "*") {
|
if (name != "*") {
|
||||||
Regex regex(name);
|
if (!regex) regex = std::shared_ptr<Regex>(new Regex(name));
|
||||||
if (!regex.matches(n.name)) return false;
|
if (!regex->matches(n.name)) return false;
|
||||||
}
|
}
|
||||||
if (version != "" && version != n.version) return false;
|
if (version != "" && version != n.version) return false;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "types.hh"
|
#include "types.hh"
|
||||||
|
#include "regex.hh"
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
@ -14,6 +17,9 @@ struct DrvName
|
||||||
DrvName();
|
DrvName();
|
||||||
DrvName(const string & s);
|
DrvName(const string & s);
|
||||||
bool matches(DrvName & n);
|
bool matches(DrvName & n);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<Regex> regex;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef list<DrvName> DrvNames;
|
typedef list<DrvName> DrvNames;
|
||||||
|
|
Loading…
Reference in a new issue