From f92219e5cd07a3ac424aa6eedb88056a8cbc2e50 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 24 Nov 2015 07:53:32 -0500 Subject: [PATCH] CmdInfo: Switched to use indices to make fewer string copies --- src/commands/CmdInfo.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/commands/CmdInfo.cpp b/src/commands/CmdInfo.cpp index d3f96aa2f..3abb22254 100644 --- a/src/commands/CmdInfo.cpp +++ b/src/commands/CmdInfo.cpp @@ -524,33 +524,32 @@ int CmdInfo::execute (std::string& output) if (context.config.getBoolean ("journal.info") && undo.size () > 3) { - // Scan the undo data for entries matching this task. - std::string when; - std::string previous; - std::string current; + // Scan the undo data for entries matching this task, without making + // copies. unsigned int i = 0; long last_timestamp = 0; while (i < undo.size ()) { - when = undo[i++]; - previous = ""; - if (undo[i].substr (0, 3) == "old") - previous = undo[i++]; + int when = i++; + int previous = -1; - current = undo[i++]; + if (! undo[i].compare (0, 3, "old", 3)) + previous = i++; + + int current = i++; i++; // Separator - if (current.find ("uuid:\"" + uuid) != std::string::npos) + if (undo[current].find ("uuid:\"" + uuid) != std::string::npos) { - if (previous != "") + if (previous != -1) { int row = journal.addRow (); - ISO8601d timestamp (strtol (when.substr (5).c_str (), NULL, 10)); + ISO8601d timestamp (strtol (undo[when].substr (5).c_str (), NULL, 10)); journal.set (row, 0, timestamp.toString (dateformat)); - Task before (previous.substr (4)); - Task after (current.substr (4)); + Task before (undo[previous].substr (4)); + Task after (undo[current].substr (4)); journal.set (row, 1, taskInfoDifferences (before, after, dateformat, last_timestamp, timestamp.toEpoch())); } }