From eb2cb99532bc9c8ede886747eb566a4da5adf4cb Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 2 Oct 2010 12:02:06 -0400 Subject: [PATCH] Performance - Removed "std::endl" in cases where the autoflush is only going to slow things down. --- src/Config.cpp | 16 +++---- src/Context.cpp | 14 +++--- src/Permission.cpp | 5 +- src/Table.cpp | 2 +- src/Tree.cpp | 4 +- src/import.cpp | 24 ++++------ src/main.cpp | 4 +- src/recur.cpp | 3 +- src/tests/sensor.t.cpp | 4 +- src/tests/test.cpp | 103 +++++++++++++++++------------------------ src/ui/interactive.cpp | 8 ++-- 11 files changed, 78 insertions(+), 109 deletions(-) diff --git a/src/Config.cpp b/src/Config.cpp index d497a940b..236bdc298 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -645,13 +645,12 @@ std::string Config::checkForDeprecatedColor () if (deprecated.size ()) { out << "Your .taskrc file contains color settings that use deprecated " - << "underscores. Please check:" - << std::endl; + << "underscores. Please check:\n"; foreach (i, deprecated) - out << " " << *i << "=" << get (*i) << std::endl; + out << " " << *i << "=" << get (*i) << "\n"; - out << std::endl; + out << "\n"; } return out.str (); @@ -674,18 +673,17 @@ std::string Config::checkForDeprecatedColumns () } std::stringstream out; - out << std::endl; + out << "\n"; if (deprecated.size ()) { out << "Your .taskrc file contains reports with deprecated columns. " - << "Please check for entry_time, start_time or end_time in:" - << std::endl; + << "Please check for entry_time, start_time or end_time in:\n"; foreach (i, deprecated) - out << " " << *i << std::endl; + out << " " << *i << "\n"; - out << std::endl; + out << "\n"; } return out.str (); diff --git a/src/Context.cpp b/src/Context.cpp index c4d10c9b8..332dc990d 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -161,9 +161,9 @@ int Context::run () if (config.getBoolean ("debug")) foreach (d, debugMessages) if (config.getBoolean ("color") || config.getBoolean ("_forcecolor")) - std::cout << colorizeDebug (*d) << std::endl; + std::cout << colorizeDebug (*d) << "\n"; else - std::cout << *d << std::endl; + std::cout << *d << "\n"; hooks.trigger ("post-debug"); // Dump all headers. @@ -171,9 +171,9 @@ int Context::run () if (config.getBoolean ("verbose")) foreach (h, headers) if (config.getBoolean ("color") || config.getBoolean ("_forcecolor")) - std::cout << colorizeHeader (*h) << std::endl; + std::cout << colorizeHeader (*h) << "\n"; else - std::cout << *h << std::endl; + std::cout << *h << "\n"; hooks.trigger ("post-header"); // Dump the report output. @@ -186,9 +186,9 @@ int Context::run () if (config.getBoolean ("verbose")) foreach (f, footnotes) if (config.getBoolean ("color") || config.getBoolean ("_forcecolor")) - std::cout << colorizeFootnote (*f) << std::endl; + std::cout << colorizeFootnote (*f) << "\n"; else - std::cout << *f << std::endl; + std::cout << *f << "\n"; hooks.trigger ("post-footnote"); hooks.trigger ("pre-exit"); @@ -763,7 +763,7 @@ void Context::parse ( else if (!foundNonSequence && (parseTask.id != 0 || parseSequence.size () != 0)) { - std::cout << "No command - assuming 'info'." << std::endl; + std::cout << "No command - assuming 'info'.\n"; parseCmd.command = "info"; } } diff --git a/src/Permission.cpp b/src/Permission.cpp index b62be6857..f9e399911 100644 --- a/src/Permission.cpp +++ b/src/Permission.cpp @@ -56,8 +56,7 @@ bool Permission::confirmed (const Task& task, const std::string& question) if (allConfirmed) return true; - std::cout << std::endl - << "Task " + std::cout << "\nTask " << task.id << " \"" << task.get ("description") @@ -69,7 +68,7 @@ bool Permission::confirmed (const Task& task, const std::string& question) std::cout << " (Recurring)"; } - std::cout << std::endl; + std::cout << std::endl; // Flush. int answer = confirm4 (question); if (answer == 2) diff --git a/src/Table.cpp b/src/Table.cpp index 1899b314a..e5ea2c070 100644 --- a/src/Table.cpp +++ b/src/Table.cpp @@ -416,7 +416,7 @@ void Table::calculateColumnWidths () } // Try again, treating minimum columns as flexible. -// std::cout << "# no flexible columns. Now what?" << std::endl; +// std::cout << "# no flexible columns. Now what?\n"; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Tree.cpp b/src/Tree.cpp index d4bfeefed..900fd9f2b 100644 --- a/src/Tree.cpp +++ b/src/Tree.cpp @@ -314,7 +314,7 @@ void Tree::dumpNode (Tree* t, int depth) if (tags.length ()) std::cout << " \033[32m" << tags << "\033[0m"; - std::cout << std::endl; + std::cout << "\n"; // Recurse for branches. for (int i = 0; i < t->branches (); ++i) @@ -324,7 +324,7 @@ void Tree::dumpNode (Tree* t, int depth) //////////////////////////////////////////////////////////////////////////////// void Tree::dump () { - std::cout << "Tree (" << count () << " nodes)" << std::endl; + std::cout << "Tree (" << count () << " nodes)\n"; dumpNode (this, 1); } diff --git a/src/import.cpp b/src/import.cpp index b89ce176a..047dbc7c5 100644 --- a/src/import.cpp +++ b/src/import.cpp @@ -337,8 +337,7 @@ static std::string importTask_1_4_3 (const std::vector & lines) << (lines.size () - failed.size () - 1) << " tasks successfully, with " << failed.size () - << " errors." - << std::endl; + << " errors.\n"; if (failed.size ()) { @@ -499,8 +498,7 @@ static std::string importTask_1_5_0 (const std::vector & lines) << (lines.size () - failed.size () - 1) << " tasks successfully, with " << failed.size () - << " errors." - << std::endl; + << " errors.\n"; if (failed.size ()) { @@ -662,8 +660,7 @@ static std::string importTask_1_6_0 (const std::vector & lines) << (lines.size () - failed.size () - 1) << " tasks successfully, with " << failed.size () - << " errors." - << std::endl; + << " errors.\n"; if (failed.size ()) { @@ -710,8 +707,7 @@ static std::string importTaskCmdLine (const std::vector & lines) << (lines.size () - failed.size ()) << " tasks successfully, with " << failed.size () - << " errors." - << std::endl; + << " errors.\n"; if (failed.size ()) { @@ -839,8 +835,7 @@ static std::string importTodoSh_2_0 (const std::vector & lines) << (lines.size () - failed.size ()) << " tasks successfully, with " << failed.size () - << " errors." - << std::endl; + << " errors.\n"; if (failed.size ()) { @@ -903,8 +898,7 @@ static std::string importText (const std::vector & lines) << count << " tasks successfully, with " << failed.size () - << " errors." - << std::endl; + << " errors.\n"; if (failed.size ()) { @@ -1149,8 +1143,7 @@ static std::string importCSV (const std::vector & lines) << (lines.size () - failed.size () - 1) << " tasks successfully, with " << failed.size () - << " errors." - << std::endl; + << " errors.\n"; if (failed.size ()) { @@ -1254,8 +1247,7 @@ static std::string importYAML (const std::vector & lines) std::stringstream out; out << "Imported " << count - << " tasks successfully." - << std::endl; + << " tasks successfully.\n"; return out.str (); } diff --git a/src/main.cpp b/src/main.cpp index 9d9145099..2ea3b5bd1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -76,13 +76,13 @@ int main (int argc, char** argv) catch (std::string& error) { - std::cout << error << std::endl; + std::cout << error << "\n"; return -1; } catch (...) { - std::cerr << context.stringtable.get (100, "Unknown error.") << std::endl; + std::cerr << context.stringtable.get (100, "Unknown error.") << "\n"; return -2; } diff --git a/src/recur.cpp b/src/recur.cpp index f2f9c235f..95bfb9fad 100644 --- a/src/recur.cpp +++ b/src/recur.cpp @@ -74,8 +74,7 @@ void handleRecurrence () { std::cout << "Task (" << trim (t->get ("description")) - << ") has past its 'until' date, and has been deleted." - << std::endl; + << ") has past its 'until' date, and has been deleted.\n"; // Determine the end date. char endTime[16]; diff --git a/src/tests/sensor.t.cpp b/src/tests/sensor.t.cpp index 4a0cac280..5314c0d79 100644 --- a/src/tests/sensor.t.cpp +++ b/src/tests/sensor.t.cpp @@ -50,7 +50,7 @@ int main (int argc, char** argv) std::ofstream one ("./sensor.foo", std::ios_base::out | std::ios_base::app); if (one.good ()) { - one << "touch" << std::endl; + one << "touch\n"; one.close (); } @@ -65,7 +65,7 @@ int main (int argc, char** argv) std::ofstream two ("./sensor.foo", std::ios_base::out | std::ios_base::app); if (two.good ()) { - two << "touch" << std::endl; + two << "touch\n"; two.close (); } diff --git a/src/tests/test.cpp b/src/tests/test.cpp index d29039138..313dec9c1 100644 --- a/src/tests/test.cpp +++ b/src/tests/test.cpp @@ -50,7 +50,7 @@ UnitTest::UnitTest (int planned) , mFailed (0) , mSkipped (0) { - std::cout << "1.." << mPlanned << std::endl; + std::cout << "1.." << mPlanned << "\n"; } /////////////////////////////////////////////////////////////////////////////// @@ -66,8 +66,7 @@ UnitTest::~UnitTest () << mCounter << " tests, out of a planned " << mPlanned - << " were run." - << std::endl; + << " were run.\n"; mSkipped += mPlanned - mCounter; } @@ -76,8 +75,7 @@ UnitTest::~UnitTest () << mCounter << " tests were run, but only " << mPlanned - << " were planned." - << std::endl; + << " were planned.\n"; std::cout << "# " << mPassed @@ -87,8 +85,7 @@ UnitTest::~UnitTest () << mSkipped << " skipped. " << std::setprecision (3) << percentPassed - << "% passed." - << std::endl; + << "% passed.\n"; } /////////////////////////////////////////////////////////////////////////////// @@ -100,14 +97,14 @@ void UnitTest::plan (int planned) mFailed = 0; mSkipped = 0; - std::cout << "1.." << mPlanned << std::endl; + std::cout << "1.." << mPlanned << "\n"; } /////////////////////////////////////////////////////////////////////////////// void UnitTest::planMore (int extra) { mPlanned += extra; - std::cout << "1.." << mPlanned << std::endl; + std::cout << "1.." << mPlanned << "\n"; } /////////////////////////////////////////////////////////////////////////////// @@ -122,7 +119,7 @@ void UnitTest::ok (bool expression, const std::string& name) << mCounter << " - " << name - << std::endl; + << "\n"; } else { @@ -131,7 +128,7 @@ void UnitTest::ok (bool expression, const std::string& name) << mCounter << " - " << name - << std::endl; + << "\n"; } } @@ -147,7 +144,7 @@ void UnitTest::notok (bool expression, const std::string& name) << mCounter << " - " << name - << std::endl; + << "\n"; } else { @@ -156,7 +153,7 @@ void UnitTest::notok (bool expression, const std::string& name) << mCounter << " - " << name - << std::endl; + << "\n"; } } @@ -171,7 +168,7 @@ void UnitTest::is (bool actual, bool expected, const std::string& name) << mCounter << " - " << name - << std::endl; + << "\n"; } else { @@ -180,13 +177,11 @@ void UnitTest::is (bool actual, bool expected, const std::string& name) << mCounter << " - " << name - << std::endl - << "# expected: " + << "\n# expected: " << expected - << std::endl - << "# got: " + << "\n# got: " << actual - << std::endl; + << "\n"; } } @@ -201,7 +196,7 @@ void UnitTest::is (size_t actual, size_t expected, const std::string& name) << mCounter << " - " << name - << std::endl; + << "\n"; } else { @@ -210,13 +205,11 @@ void UnitTest::is (size_t actual, size_t expected, const std::string& name) << mCounter << " - " << name - << std::endl - << "# expected: " + << "\n# expected: " << expected - << std::endl - << "# got: " + << "\n# got: " << actual - << std::endl; + << "\n"; } } @@ -231,7 +224,7 @@ void UnitTest::is (int actual, int expected, const std::string& name) << mCounter << " - " << name - << std::endl; + << "\n"; } else { @@ -240,13 +233,11 @@ void UnitTest::is (int actual, int expected, const std::string& name) << mCounter << " - " << name - << std::endl - << "# expected: " + << "\n# expected: " << expected - << std::endl - << "# got: " + << "\n# got: " << actual - << std::endl; + << "\n"; } } @@ -261,7 +252,7 @@ void UnitTest::is (double actual, double expected, const std::string& name) << mCounter << " - " << name - << std::endl; + << "\n"; } else { @@ -270,13 +261,11 @@ void UnitTest::is (double actual, double expected, const std::string& name) << mCounter << " - " << name - << std::endl - << "# expected: " + << "\n# expected: " << expected - << std::endl - << "# got: " + << "\n# got: " << actual - << std::endl; + << "\n"; } } @@ -291,7 +280,7 @@ void UnitTest::is (char actual, char expected, const std::string& name) << mCounter << " - " << name - << std::endl; + << "\n"; } else { @@ -300,13 +289,11 @@ void UnitTest::is (char actual, char expected, const std::string& name) << mCounter << " - " << name - << std::endl - << "# expected: " + << "\n# expected: " << expected - << std::endl - << "# got: " + << "\n# got: " << actual - << std::endl; + << "\n"; } } @@ -324,7 +311,7 @@ void UnitTest::is ( << mCounter << " - " << name - << std::endl; + << "\n"; } else { @@ -333,15 +320,12 @@ void UnitTest::is ( << mCounter << " - " << name - << std::endl - << "# expected: '" + << "\n# expected: '" << expected << "'" - << std::endl - << "# got: '" + << "\n# got: '" << actual - << "'" - << std::endl; + << "'\n"; } } @@ -359,7 +343,7 @@ void UnitTest::is ( << mCounter << " - " << name - << std::endl; + << "\n"; } else { @@ -368,15 +352,12 @@ void UnitTest::is ( << mCounter << " - " << name - << std::endl - << "# expected: '" + << "\n# expected: '" << expected << "'" - << std::endl - << "# got: '" + << "\n# got: '" << actual - << "'" - << std::endl; + << "'\n"; } } @@ -385,7 +366,7 @@ void UnitTest::diag (const std::string& text) { std::string trimmed = trim (text, " \t\n\r\f"); - std::cout << "# " << trimmed << std::endl; + std::cout << "# " << trimmed << "\n"; } /////////////////////////////////////////////////////////////////////////////// @@ -397,7 +378,7 @@ void UnitTest::pass (const std::string& text) << mCounter << " " << text - << std::endl; + << "\n"; } /////////////////////////////////////////////////////////////////////////////// @@ -409,7 +390,7 @@ void UnitTest::fail (const std::string& text) << mCounter << " " << text - << std::endl; + << "\n"; } /////////////////////////////////////////////////////////////////////////////// @@ -421,7 +402,7 @@ void UnitTest::skip (const std::string& text) << mCounter << " " << text - << std::endl; + << "\n"; } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/ui/interactive.cpp b/src/ui/interactive.cpp index 847eece20..40a88fb75 100644 --- a/src/ui/interactive.cpp +++ b/src/ui/interactive.cpp @@ -68,10 +68,10 @@ int Context::handleInteractive () } // TODO Integrate regular task error handling, using Context::debug. - catch (int e) { std::cout << e << std::endl; } - catch (const char* e) { std::cout << e << std::endl; } - catch (std::string& e) { std::cout << e << std::endl; } - catch (...) { std::cout << "Unknown error." << std::endl; } + catch (int e) { std::cout << e << "\n"; } + catch (const char* e) { std::cout << e << "\n"; } + catch (std::string& e) { std::cout << e << "\n"; } + catch (...) { std::cout << "Unknown error.\n"; } logWrite ("---");