mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Performance
- Implemented Task::get_ref, which is a lower-cost attribute accessor. - Called this in a few places.
This commit is contained in:
parent
0c0f767688
commit
b5f4fa03d2
3 changed files with 23 additions and 14 deletions
14
src/Task.cpp
14
src/Task.cpp
|
@ -237,6 +237,16 @@ const std::string Task::get (const std::string& name) const
|
|||
return "";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
const std::string& Task::get_ref (const std::string& name) const
|
||||
{
|
||||
Task::const_iterator i = this->find (name);
|
||||
if (i != this->end ())
|
||||
return i->second;
|
||||
|
||||
return dummy;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Task::get_int (const std::string& name) const
|
||||
{
|
||||
|
@ -1375,7 +1385,7 @@ float Task::urgency ()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
float Task::urgency_priority () const
|
||||
{
|
||||
std::string value = get ("priority");
|
||||
const std::string& value = get_ref ("priority");
|
||||
|
||||
if (value == "H") return 1.0;
|
||||
else if (value == "M") return 0.65;
|
||||
|
@ -1405,7 +1415,7 @@ float Task::urgency_active () const
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
float Task::urgency_waiting () const
|
||||
{
|
||||
if (get ("status") == "waiting")
|
||||
if (get_ref ("status") == "waiting")
|
||||
return 1.0;
|
||||
|
||||
return 0.0;
|
||||
|
|
|
@ -70,6 +70,7 @@ public:
|
|||
bool has (const std::string&) const;
|
||||
std::vector <std::string> all ();
|
||||
const std::string get (const std::string&) const;
|
||||
const std::string& get_ref (const std::string&) const;
|
||||
int get_int (const std::string&) const;
|
||||
unsigned long get_ulong (const std::string&) const;
|
||||
time_t get_date (const std::string&) const;
|
||||
|
|
22
src/sort.cpp
22
src/sort.cpp
|
@ -74,8 +74,6 @@ static bool sort_compare (int left, int right)
|
|||
|
||||
int left_number;
|
||||
int right_number;
|
||||
std::string left_string;
|
||||
std::string right_string;
|
||||
float left_real;
|
||||
float right_real;
|
||||
char left_char;
|
||||
|
@ -105,8 +103,8 @@ static bool sort_compare (int left, int right)
|
|||
else if (field == "depends")
|
||||
{
|
||||
// Raw data is a comma-separated list of uuids
|
||||
left_string = (*global_data)[left].get (field);
|
||||
right_string = (*global_data)[right].get (field);
|
||||
const std::string& left_string = (*global_data)[left].get_ref (field);
|
||||
const std::string& right_string = (*global_data)[right].get_ref (field);
|
||||
|
||||
if (left_string == right_string)
|
||||
continue;
|
||||
|
@ -137,8 +135,8 @@ static bool sort_compare (int left, int right)
|
|||
field == "tags" ||
|
||||
field == "uuid")
|
||||
{
|
||||
left_string = (*global_data)[left].get (field);
|
||||
right_string = (*global_data)[right].get (field);
|
||||
const std::string& left_string = (*global_data)[left].get_ref (field);
|
||||
const std::string& right_string = (*global_data)[right].get_ref (field);
|
||||
|
||||
if (left_string == right_string)
|
||||
continue;
|
||||
|
@ -171,8 +169,8 @@ static bool sort_compare (int left, int right)
|
|||
// Due Date.
|
||||
else if (field == "due")
|
||||
{
|
||||
left_string = (*global_data)[left].get (field);
|
||||
right_string = (*global_data)[right].get (field);
|
||||
const std::string& left_string = (*global_data)[left].get_ref (field);
|
||||
const std::string& right_string = (*global_data)[right].get_ref (field);
|
||||
|
||||
if (left_string != "" && right_string == "")
|
||||
return true;
|
||||
|
@ -196,8 +194,8 @@ static bool sort_compare (int left, int right)
|
|||
field == "until" ||
|
||||
field == "wait")
|
||||
{
|
||||
left_string = (*global_data)[left].get (field);
|
||||
right_string = (*global_data)[right].get (field);
|
||||
const std::string& left_string = (*global_data)[left].get_ref (field);
|
||||
const std::string& right_string = (*global_data)[right].get_ref (field);
|
||||
|
||||
if (left_string == right_string)
|
||||
continue;
|
||||
|
@ -211,8 +209,8 @@ static bool sort_compare (int left, int right)
|
|||
// Duration.
|
||||
else if (field == "recur")
|
||||
{
|
||||
left_string = (*global_data)[left].get (field);
|
||||
right_string = (*global_data)[right].get (field);
|
||||
const std::string& left_string = (*global_data)[left].get_ref (field);
|
||||
const std::string& right_string = (*global_data)[right].get_ref (field);
|
||||
|
||||
if (left_string == right_string)
|
||||
continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue