mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-09-07 11:57:23 +02:00
DOM: Create a copy of Task object only if needed
This commit is contained in:
parent
87b0be9b6f
commit
95b135b59e
1 changed files with 44 additions and 24 deletions
68
src/DOM.cpp
68
src/DOM.cpp
|
@ -260,36 +260,56 @@ bool getDOM (const std::string& name, const Task& task, Variant& value)
|
||||||
|
|
||||||
// split name on '.'
|
// split name on '.'
|
||||||
auto elements = split (name, '.');
|
auto elements = split (name, '.');
|
||||||
|
Task loaded_task;
|
||||||
|
|
||||||
Task ref (task);
|
// Use a lambda to decide whether the reference is going to be the passed
|
||||||
Lexer lexer (elements[0]);
|
// "task" or whether it's going to be a newly loaded task (if id/uuid was
|
||||||
std::string token;
|
// given).
|
||||||
Lexer::Type type;
|
const Task& ref = [&]() -> const Task&
|
||||||
|
|
||||||
// If this can be ID/UUID reference (the name contains '.'),
|
|
||||||
// lex it to figure out. Otherwise don't lex, as lexing can be slow.
|
|
||||||
if ((elements.size() > 1) and lexer.token (token, type))
|
|
||||||
{
|
{
|
||||||
if (type == Lexer::Type::uuid &&
|
Lexer lexer (elements[0]);
|
||||||
token.length () == elements[0].length ())
|
std::string token;
|
||||||
{
|
Lexer::Type type;
|
||||||
if (token != ref.get ("uuid"))
|
|
||||||
Context::getContext ().tdb2.get (token, ref);
|
|
||||||
|
|
||||||
// Eat elements[0]/UUID.
|
// If this can be ID/UUID reference (the name contains '.'),
|
||||||
elements.erase (elements.begin ());
|
// lex it to figure out. Otherwise don't lex, as lexing can be slow.
|
||||||
}
|
if ((elements.size() > 1) and lexer.token (token, type))
|
||||||
else if (type == Lexer::Type::number &&
|
|
||||||
token.find ('.') == std::string::npos)
|
|
||||||
{
|
{
|
||||||
auto id = strtol (token.c_str (), nullptr, 10);
|
bool reloaded = false;
|
||||||
if (id && id != ref.id)
|
|
||||||
Context::getContext ().tdb2.get (id, ref);
|
|
||||||
|
|
||||||
// Eat elements[0]/ID.
|
if (type == Lexer::Type::uuid &&
|
||||||
elements.erase (elements.begin ());
|
token.length () == elements[0].length ())
|
||||||
|
{
|
||||||
|
if (token != task.get ("uuid"))
|
||||||
|
{
|
||||||
|
Context::getContext ().tdb2.get (token, loaded_task);
|
||||||
|
reloaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Eat elements[0]/UUID.
|
||||||
|
elements.erase (elements.begin ());
|
||||||
|
}
|
||||||
|
else if (type == Lexer::Type::number &&
|
||||||
|
token.find ('.') == std::string::npos)
|
||||||
|
{
|
||||||
|
auto id = strtol (token.c_str (), nullptr, 10);
|
||||||
|
if (id && id != task.id)
|
||||||
|
{
|
||||||
|
Context::getContext ().tdb2.get (id, loaded_task);
|
||||||
|
reloaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Eat elements[0]/ID.
|
||||||
|
elements.erase (elements.begin ());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reloaded)
|
||||||
|
return loaded_task;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return task;
|
||||||
|
|
||||||
|
} ();
|
||||||
|
|
||||||
auto size = elements.size ();
|
auto size = elements.size ();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue