DOM: Factored out element size

This commit is contained in:
Paul Beckingham 2015-09-07 15:13:12 -04:00
parent 3b4dc9acb3
commit 992cb6369a

View file

@ -192,6 +192,7 @@ bool DOM::get (const std::string& name, Variant& value)
// annotations.<N>.entry // annotations.<N>.entry
// annotations.<N>.description // annotations.<N>.description
// //
// This code emphasizes speed, hence 'id' being evaluated first.
bool DOM::get (const std::string& name, const Task& task, Variant& value) bool DOM::get (const std::string& name, const Task& task, Variant& value)
{ {
// <attr> // <attr>
@ -210,8 +211,9 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value)
// split name on '.' // split name on '.'
std::vector <std::string> elements; std::vector <std::string> elements;
split (elements, name, '.'); split (elements, name, '.');
auto size = elements.size ();
if (elements.size () == 1) if (size == 1)
{ {
std::string canonical; std::string canonical;
if (task.size () && context.cli2.canonicalize (canonical, "attribute", name)) if (task.size () && context.cli2.canonicalize (canonical, "attribute", name))
@ -244,7 +246,7 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value)
} }
} }
} }
else if (elements.size () > 1) else if (size > 1)
{ {
Task ref; Task ref;
@ -292,7 +294,7 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value)
std::string canonical; std::string canonical;
if (context.cli2.canonicalize (canonical, "attribute", elements[1])) if (context.cli2.canonicalize (canonical, "attribute", elements[1]))
{ {
if (elements.size () == 2) if (size == 2)
{ {
Column* column = context.columns[canonical]; Column* column = context.columns[canonical];
if (column) if (column)
@ -333,7 +335,7 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value)
return true; return true;
} }
} }
else if (elements.size () == 3) else if (size == 3)
{ {
// tags.<tag> // tags.<tag>
if (canonical == "tags") if (canonical == "tags")
@ -369,7 +371,7 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value)
} }
else if (elements[1] == "annotations") else if (elements[1] == "annotations")
{ {
if (elements.size () == 4) if (size == 4)
{ {
std::map <std::string, std::string> annos; std::map <std::string, std::string> annos;
ref.getAnnotations (annos); ref.getAnnotations (annos);
@ -397,7 +399,7 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value)
} }
} }
} }
else if (elements.size () == 5) else if (size == 5)
{ {
std::map <std::string, std::string> annos; std::map <std::string, std::string> annos;
ref.getAnnotations (annos); ref.getAnnotations (annos);