From 4865269630ceccff8c32a2fd420c0aadda98f970 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 25 Jan 2015 10:33:03 -0500 Subject: [PATCH] Hooks - Modified loop so it no longer walks the whole list unnecessarily. - Minor style tweaks. --- src/Hooks.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 68e5db4d1..bbe7f7d62 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -344,7 +344,7 @@ void Hooks::onModify (const Task& before, std::vector & tasks) { if (status == 0) { - if (JSONContainsUUID((*line), before.get("uuid"))) + if (JSONContainsUUID ((*line), before.get ("uuid"))) input[1] = *line; // [1] original' else input.push_back (*line); // [n > 1] extras @@ -461,10 +461,8 @@ bool Hooks::isJSON (const std::string& input) const //////////////////////////////////////////////////////////////////////////////// // This method assumes that input has already been validated with isJSON method -bool Hooks::JSONContainsUUID(const std::string& input, const std::string& uuid) const +bool Hooks::JSONContainsUUID (const std::string& input, const std::string& uuid) const { - bool foundUUID = false; - // Parse the whole thing. json::object* root_obj = (json::object*) (json::parse (input)); @@ -476,12 +474,15 @@ bool Hooks::JSONContainsUUID(const std::string& input, const std::string& uuid) { // If the attribute is a recognized column. std::string type = Task::attributes[i->first]; - if (type == "string" && i->first == "uuid" && + if (type == "string" && + i->first == "uuid" && json::decode (unquoteText (i->second->dump ())) == uuid) - foundUUID = true; + { + return true; + } } - return foundUUID; + return false; } ////////////////////////////////////////////////////////////////////////////////