From b5f4fa03d295e1de1d89cac0ca36357c2ef1a169 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 28 Apr 2012 18:01:40 -0400 Subject: [PATCH] Performance - Implemented Task::get_ref, which is a lower-cost attribute accessor. - Called this in a few places. --- src/Task.cpp | 14 ++++++++++++-- src/Task.h | 1 + src/sort.cpp | 22 ++++++++++------------ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/Task.cpp b/src/Task.cpp index bf1651632..4268f754d 100644 --- a/src/Task.cpp +++ b/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; diff --git a/src/Task.h b/src/Task.h index d37153e86..87f33d8bf 100644 --- a/src/Task.h +++ b/src/Task.h @@ -70,6 +70,7 @@ public: bool has (const std::string&) const; std::vector 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; diff --git a/src/sort.cpp b/src/sort.cpp index 320f9d9cb..889801970 100644 --- a/src/sort.cpp +++ b/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;