Don't recompile the same regex over and over

This commit is contained in:
Eelco Dolstra 2014-10-03 21:29:20 +02:00
parent 104e55bb7f
commit 3b5fa8d50c
2 changed files with 8 additions and 3 deletions

View file

@ -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<Regex>(new Regex(name));
if (!regex->matches(n.name)) return false;
}
if (version != "" && version != n.version) return false;
return true;

View file

@ -1,6 +1,9 @@
#pragma once
#include <memory>
#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> regex;
};
typedef list<DrvName> DrvNames;