mirror of
https://github.com/NixOS/nix
synced 2025-06-27 04:21:16 +02:00
nix search: Add a cache
The package list is now cached in ~/.cache/nix/package-search.json. This gives a substantial speedup to "nix search" queries. For example (on an SSD): First run: (no package search cache, cold page cache) $ time nix search blender Attribute name: nixpkgs.blender Package name: blender Version: 2.78c Description: 3D Creation/Animation/Publishing System real 0m6.516s Second run: (package search cache populated) $ time nix search blender Attribute name: nixpkgs.blender Package name: blender Version: 2.78c Description: 3D Creation/Animation/Publishing System real 0m0.143s
This commit is contained in:
parent
4c9ff89c26
commit
57b9505731
3 changed files with 92 additions and 20 deletions
|
@ -50,20 +50,22 @@ template<> void toJSON<std::nullptr_t>(std::ostream & str, const std::nullptr_t
|
|||
JSONWriter::JSONWriter(std::ostream & str, bool indent)
|
||||
: state(new JSONState(str, indent))
|
||||
{
|
||||
state->stack.push_back(this);
|
||||
state->stack++;
|
||||
}
|
||||
|
||||
JSONWriter::JSONWriter(JSONState * state)
|
||||
: state(state)
|
||||
{
|
||||
state->stack.push_back(this);
|
||||
state->stack++;
|
||||
}
|
||||
|
||||
JSONWriter::~JSONWriter()
|
||||
{
|
||||
assertActive();
|
||||
state->stack.pop_back();
|
||||
if (state->stack.empty()) delete state;
|
||||
if (state) {
|
||||
assertActive();
|
||||
state->stack--;
|
||||
if (state->stack == 0) delete state;
|
||||
}
|
||||
}
|
||||
|
||||
void JSONWriter::comma()
|
||||
|
@ -121,9 +123,11 @@ void JSONObject::open()
|
|||
|
||||
JSONObject::~JSONObject()
|
||||
{
|
||||
state->depth--;
|
||||
if (state->indent && !first) indent();
|
||||
state->str << "}";
|
||||
if (state) {
|
||||
state->depth--;
|
||||
if (state->indent && !first) indent();
|
||||
state->str << "}";
|
||||
}
|
||||
}
|
||||
|
||||
void JSONObject::attr(const std::string & s)
|
||||
|
|
|
@ -21,11 +21,11 @@ protected:
|
|||
std::ostream & str;
|
||||
bool indent;
|
||||
size_t depth = 0;
|
||||
std::vector<JSONWriter *> stack;
|
||||
size_t stack = 0;
|
||||
JSONState(std::ostream & str, bool indent) : str(str), indent(indent) { }
|
||||
~JSONState()
|
||||
{
|
||||
assert(stack.empty());
|
||||
assert(stack == 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -41,7 +41,7 @@ protected:
|
|||
|
||||
void assertActive()
|
||||
{
|
||||
assert(!state->stack.empty() && state->stack.back() == this);
|
||||
assert(state->stack != 0);
|
||||
}
|
||||
|
||||
void comma();
|
||||
|
@ -117,6 +117,14 @@ public:
|
|||
open();
|
||||
}
|
||||
|
||||
JSONObject(const JSONObject & obj) = delete;
|
||||
|
||||
JSONObject(JSONObject && obj)
|
||||
: JSONWriter(obj.state)
|
||||
{
|
||||
obj.state = 0;
|
||||
}
|
||||
|
||||
~JSONObject();
|
||||
|
||||
template<typename T>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue