Performance

- Removed "std::endl" in cases where the autoflush is only going to
  slow things down.
This commit is contained in:
Paul Beckingham 2010-10-02 12:02:06 -04:00
parent 1d3aa891d6
commit eb2cb99532
11 changed files with 78 additions and 109 deletions

View file

@ -645,13 +645,12 @@ std::string Config::checkForDeprecatedColor ()
if (deprecated.size ()) if (deprecated.size ())
{ {
out << "Your .taskrc file contains color settings that use deprecated " out << "Your .taskrc file contains color settings that use deprecated "
<< "underscores. Please check:" << "underscores. Please check:\n";
<< std::endl;
foreach (i, deprecated) foreach (i, deprecated)
out << " " << *i << "=" << get (*i) << std::endl; out << " " << *i << "=" << get (*i) << "\n";
out << std::endl; out << "\n";
} }
return out.str (); return out.str ();
@ -674,18 +673,17 @@ std::string Config::checkForDeprecatedColumns ()
} }
std::stringstream out; std::stringstream out;
out << std::endl; out << "\n";
if (deprecated.size ()) if (deprecated.size ())
{ {
out << "Your .taskrc file contains reports with deprecated columns. " out << "Your .taskrc file contains reports with deprecated columns. "
<< "Please check for entry_time, start_time or end_time in:" << "Please check for entry_time, start_time or end_time in:\n";
<< std::endl;
foreach (i, deprecated) foreach (i, deprecated)
out << " " << *i << std::endl; out << " " << *i << "\n";
out << std::endl; out << "\n";
} }
return out.str (); return out.str ();

View file

@ -161,9 +161,9 @@ int Context::run ()
if (config.getBoolean ("debug")) if (config.getBoolean ("debug"))
foreach (d, debugMessages) foreach (d, debugMessages)
if (config.getBoolean ("color") || config.getBoolean ("_forcecolor")) if (config.getBoolean ("color") || config.getBoolean ("_forcecolor"))
std::cout << colorizeDebug (*d) << std::endl; std::cout << colorizeDebug (*d) << "\n";
else else
std::cout << *d << std::endl; std::cout << *d << "\n";
hooks.trigger ("post-debug"); hooks.trigger ("post-debug");
// Dump all headers. // Dump all headers.
@ -171,9 +171,9 @@ int Context::run ()
if (config.getBoolean ("verbose")) if (config.getBoolean ("verbose"))
foreach (h, headers) foreach (h, headers)
if (config.getBoolean ("color") || config.getBoolean ("_forcecolor")) if (config.getBoolean ("color") || config.getBoolean ("_forcecolor"))
std::cout << colorizeHeader (*h) << std::endl; std::cout << colorizeHeader (*h) << "\n";
else else
std::cout << *h << std::endl; std::cout << *h << "\n";
hooks.trigger ("post-header"); hooks.trigger ("post-header");
// Dump the report output. // Dump the report output.
@ -186,9 +186,9 @@ int Context::run ()
if (config.getBoolean ("verbose")) if (config.getBoolean ("verbose"))
foreach (f, footnotes) foreach (f, footnotes)
if (config.getBoolean ("color") || config.getBoolean ("_forcecolor")) if (config.getBoolean ("color") || config.getBoolean ("_forcecolor"))
std::cout << colorizeFootnote (*f) << std::endl; std::cout << colorizeFootnote (*f) << "\n";
else else
std::cout << *f << std::endl; std::cout << *f << "\n";
hooks.trigger ("post-footnote"); hooks.trigger ("post-footnote");
hooks.trigger ("pre-exit"); hooks.trigger ("pre-exit");
@ -763,7 +763,7 @@ void Context::parse (
else if (!foundNonSequence && else if (!foundNonSequence &&
(parseTask.id != 0 || parseSequence.size () != 0)) (parseTask.id != 0 || parseSequence.size () != 0))
{ {
std::cout << "No command - assuming 'info'." << std::endl; std::cout << "No command - assuming 'info'.\n";
parseCmd.command = "info"; parseCmd.command = "info";
} }
} }

View file

@ -56,8 +56,7 @@ bool Permission::confirmed (const Task& task, const std::string& question)
if (allConfirmed) if (allConfirmed)
return true; return true;
std::cout << std::endl std::cout << "\nTask "
<< "Task "
<< task.id << task.id
<< " \"" << " \""
<< task.get ("description") << task.get ("description")
@ -69,7 +68,7 @@ bool Permission::confirmed (const Task& task, const std::string& question)
std::cout << " (Recurring)"; std::cout << " (Recurring)";
} }
std::cout << std::endl; std::cout << std::endl; // Flush.
int answer = confirm4 (question); int answer = confirm4 (question);
if (answer == 2) if (answer == 2)

View file

@ -416,7 +416,7 @@ void Table::calculateColumnWidths ()
} }
// Try again, treating minimum columns as flexible. // Try again, treating minimum columns as flexible.
// std::cout << "# no flexible columns. Now what?" << std::endl; // std::cout << "# no flexible columns. Now what?\n";
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -314,7 +314,7 @@ void Tree::dumpNode (Tree* t, int depth)
if (tags.length ()) if (tags.length ())
std::cout << " \033[32m" << tags << "\033[0m"; std::cout << " \033[32m" << tags << "\033[0m";
std::cout << std::endl; std::cout << "\n";
// Recurse for branches. // Recurse for branches.
for (int i = 0; i < t->branches (); ++i) for (int i = 0; i < t->branches (); ++i)
@ -324,7 +324,7 @@ void Tree::dumpNode (Tree* t, int depth)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Tree::dump () void Tree::dump ()
{ {
std::cout << "Tree (" << count () << " nodes)" << std::endl; std::cout << "Tree (" << count () << " nodes)\n";
dumpNode (this, 1); dumpNode (this, 1);
} }

View file

@ -337,8 +337,7 @@ static std::string importTask_1_4_3 (const std::vector <std::string>& lines)
<< (lines.size () - failed.size () - 1) << (lines.size () - failed.size () - 1)
<< " tasks successfully, with " << " tasks successfully, with "
<< failed.size () << failed.size ()
<< " errors." << " errors.\n";
<< std::endl;
if (failed.size ()) if (failed.size ())
{ {
@ -499,8 +498,7 @@ static std::string importTask_1_5_0 (const std::vector <std::string>& lines)
<< (lines.size () - failed.size () - 1) << (lines.size () - failed.size () - 1)
<< " tasks successfully, with " << " tasks successfully, with "
<< failed.size () << failed.size ()
<< " errors." << " errors.\n";
<< std::endl;
if (failed.size ()) if (failed.size ())
{ {
@ -662,8 +660,7 @@ static std::string importTask_1_6_0 (const std::vector <std::string>& lines)
<< (lines.size () - failed.size () - 1) << (lines.size () - failed.size () - 1)
<< " tasks successfully, with " << " tasks successfully, with "
<< failed.size () << failed.size ()
<< " errors." << " errors.\n";
<< std::endl;
if (failed.size ()) if (failed.size ())
{ {
@ -710,8 +707,7 @@ static std::string importTaskCmdLine (const std::vector <std::string>& lines)
<< (lines.size () - failed.size ()) << (lines.size () - failed.size ())
<< " tasks successfully, with " << " tasks successfully, with "
<< failed.size () << failed.size ()
<< " errors." << " errors.\n";
<< std::endl;
if (failed.size ()) if (failed.size ())
{ {
@ -839,8 +835,7 @@ static std::string importTodoSh_2_0 (const std::vector <std::string>& lines)
<< (lines.size () - failed.size ()) << (lines.size () - failed.size ())
<< " tasks successfully, with " << " tasks successfully, with "
<< failed.size () << failed.size ()
<< " errors." << " errors.\n";
<< std::endl;
if (failed.size ()) if (failed.size ())
{ {
@ -903,8 +898,7 @@ static std::string importText (const std::vector <std::string>& lines)
<< count << count
<< " tasks successfully, with " << " tasks successfully, with "
<< failed.size () << failed.size ()
<< " errors." << " errors.\n";
<< std::endl;
if (failed.size ()) if (failed.size ())
{ {
@ -1149,8 +1143,7 @@ static std::string importCSV (const std::vector <std::string>& lines)
<< (lines.size () - failed.size () - 1) << (lines.size () - failed.size () - 1)
<< " tasks successfully, with " << " tasks successfully, with "
<< failed.size () << failed.size ()
<< " errors." << " errors.\n";
<< std::endl;
if (failed.size ()) if (failed.size ())
{ {
@ -1254,8 +1247,7 @@ static std::string importYAML (const std::vector <std::string>& lines)
std::stringstream out; std::stringstream out;
out << "Imported " out << "Imported "
<< count << count
<< " tasks successfully." << " tasks successfully.\n";
<< std::endl;
return out.str (); return out.str ();
} }

View file

@ -76,13 +76,13 @@ int main (int argc, char** argv)
catch (std::string& error) catch (std::string& error)
{ {
std::cout << error << std::endl; std::cout << error << "\n";
return -1; return -1;
} }
catch (...) catch (...)
{ {
std::cerr << context.stringtable.get (100, "Unknown error.") << std::endl; std::cerr << context.stringtable.get (100, "Unknown error.") << "\n";
return -2; return -2;
} }

View file

@ -74,8 +74,7 @@ void handleRecurrence ()
{ {
std::cout << "Task (" std::cout << "Task ("
<< trim (t->get ("description")) << trim (t->get ("description"))
<< ") has past its 'until' date, and has been deleted." << ") has past its 'until' date, and has been deleted.\n";
<< std::endl;
// Determine the end date. // Determine the end date.
char endTime[16]; char endTime[16];

View file

@ -50,7 +50,7 @@ int main (int argc, char** argv)
std::ofstream one ("./sensor.foo", std::ios_base::out | std::ios_base::app); std::ofstream one ("./sensor.foo", std::ios_base::out | std::ios_base::app);
if (one.good ()) if (one.good ())
{ {
one << "touch" << std::endl; one << "touch\n";
one.close (); 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); std::ofstream two ("./sensor.foo", std::ios_base::out | std::ios_base::app);
if (two.good ()) if (two.good ())
{ {
two << "touch" << std::endl; two << "touch\n";
two.close (); two.close ();
} }

View file

@ -50,7 +50,7 @@ UnitTest::UnitTest (int planned)
, mFailed (0) , mFailed (0)
, mSkipped (0) , mSkipped (0)
{ {
std::cout << "1.." << mPlanned << std::endl; std::cout << "1.." << mPlanned << "\n";
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -66,8 +66,7 @@ UnitTest::~UnitTest ()
<< mCounter << mCounter
<< " tests, out of a planned " << " tests, out of a planned "
<< mPlanned << mPlanned
<< " were run." << " were run.\n";
<< std::endl;
mSkipped += mPlanned - mCounter; mSkipped += mPlanned - mCounter;
} }
@ -76,8 +75,7 @@ UnitTest::~UnitTest ()
<< mCounter << mCounter
<< " tests were run, but only " << " tests were run, but only "
<< mPlanned << mPlanned
<< " were planned." << " were planned.\n";
<< std::endl;
std::cout << "# " std::cout << "# "
<< mPassed << mPassed
@ -87,8 +85,7 @@ UnitTest::~UnitTest ()
<< mSkipped << mSkipped
<< " skipped. " << " skipped. "
<< std::setprecision (3) << percentPassed << std::setprecision (3) << percentPassed
<< "% passed." << "% passed.\n";
<< std::endl;
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -100,14 +97,14 @@ void UnitTest::plan (int planned)
mFailed = 0; mFailed = 0;
mSkipped = 0; mSkipped = 0;
std::cout << "1.." << mPlanned << std::endl; std::cout << "1.." << mPlanned << "\n";
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
void UnitTest::planMore (int extra) void UnitTest::planMore (int extra)
{ {
mPlanned += 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 << mCounter
<< " - " << " - "
<< name << name
<< std::endl; << "\n";
} }
else else
{ {
@ -131,7 +128,7 @@ void UnitTest::ok (bool expression, const std::string& name)
<< mCounter << mCounter
<< " - " << " - "
<< name << name
<< std::endl; << "\n";
} }
} }
@ -147,7 +144,7 @@ void UnitTest::notok (bool expression, const std::string& name)
<< mCounter << mCounter
<< " - " << " - "
<< name << name
<< std::endl; << "\n";
} }
else else
{ {
@ -156,7 +153,7 @@ void UnitTest::notok (bool expression, const std::string& name)
<< mCounter << mCounter
<< " - " << " - "
<< name << name
<< std::endl; << "\n";
} }
} }
@ -171,7 +168,7 @@ void UnitTest::is (bool actual, bool expected, const std::string& name)
<< mCounter << mCounter
<< " - " << " - "
<< name << name
<< std::endl; << "\n";
} }
else else
{ {
@ -180,13 +177,11 @@ void UnitTest::is (bool actual, bool expected, const std::string& name)
<< mCounter << mCounter
<< " - " << " - "
<< name << name
<< std::endl << "\n# expected: "
<< "# expected: "
<< expected << expected
<< std::endl << "\n# got: "
<< "# got: "
<< actual << actual
<< std::endl; << "\n";
} }
} }
@ -201,7 +196,7 @@ void UnitTest::is (size_t actual, size_t expected, const std::string& name)
<< mCounter << mCounter
<< " - " << " - "
<< name << name
<< std::endl; << "\n";
} }
else else
{ {
@ -210,13 +205,11 @@ void UnitTest::is (size_t actual, size_t expected, const std::string& name)
<< mCounter << mCounter
<< " - " << " - "
<< name << name
<< std::endl << "\n# expected: "
<< "# expected: "
<< expected << expected
<< std::endl << "\n# got: "
<< "# got: "
<< actual << actual
<< std::endl; << "\n";
} }
} }
@ -231,7 +224,7 @@ void UnitTest::is (int actual, int expected, const std::string& name)
<< mCounter << mCounter
<< " - " << " - "
<< name << name
<< std::endl; << "\n";
} }
else else
{ {
@ -240,13 +233,11 @@ void UnitTest::is (int actual, int expected, const std::string& name)
<< mCounter << mCounter
<< " - " << " - "
<< name << name
<< std::endl << "\n# expected: "
<< "# expected: "
<< expected << expected
<< std::endl << "\n# got: "
<< "# got: "
<< actual << actual
<< std::endl; << "\n";
} }
} }
@ -261,7 +252,7 @@ void UnitTest::is (double actual, double expected, const std::string& name)
<< mCounter << mCounter
<< " - " << " - "
<< name << name
<< std::endl; << "\n";
} }
else else
{ {
@ -270,13 +261,11 @@ void UnitTest::is (double actual, double expected, const std::string& name)
<< mCounter << mCounter
<< " - " << " - "
<< name << name
<< std::endl << "\n# expected: "
<< "# expected: "
<< expected << expected
<< std::endl << "\n# got: "
<< "# got: "
<< actual << actual
<< std::endl; << "\n";
} }
} }
@ -291,7 +280,7 @@ void UnitTest::is (char actual, char expected, const std::string& name)
<< mCounter << mCounter
<< " - " << " - "
<< name << name
<< std::endl; << "\n";
} }
else else
{ {
@ -300,13 +289,11 @@ void UnitTest::is (char actual, char expected, const std::string& name)
<< mCounter << mCounter
<< " - " << " - "
<< name << name
<< std::endl << "\n# expected: "
<< "# expected: "
<< expected << expected
<< std::endl << "\n# got: "
<< "# got: "
<< actual << actual
<< std::endl; << "\n";
} }
} }
@ -324,7 +311,7 @@ void UnitTest::is (
<< mCounter << mCounter
<< " - " << " - "
<< name << name
<< std::endl; << "\n";
} }
else else
{ {
@ -333,15 +320,12 @@ void UnitTest::is (
<< mCounter << mCounter
<< " - " << " - "
<< name << name
<< std::endl << "\n# expected: '"
<< "# expected: '"
<< expected << expected
<< "'" << "'"
<< std::endl << "\n# got: '"
<< "# got: '"
<< actual << actual
<< "'" << "'\n";
<< std::endl;
} }
} }
@ -359,7 +343,7 @@ void UnitTest::is (
<< mCounter << mCounter
<< " - " << " - "
<< name << name
<< std::endl; << "\n";
} }
else else
{ {
@ -368,15 +352,12 @@ void UnitTest::is (
<< mCounter << mCounter
<< " - " << " - "
<< name << name
<< std::endl << "\n# expected: '"
<< "# expected: '"
<< expected << expected
<< "'" << "'"
<< std::endl << "\n# got: '"
<< "# got: '"
<< actual << actual
<< "'" << "'\n";
<< std::endl;
} }
} }
@ -385,7 +366,7 @@ void UnitTest::diag (const std::string& text)
{ {
std::string trimmed = trim (text, " \t\n\r\f"); 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 << mCounter
<< " " << " "
<< text << text
<< std::endl; << "\n";
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -409,7 +390,7 @@ void UnitTest::fail (const std::string& text)
<< mCounter << mCounter
<< " " << " "
<< text << text
<< std::endl; << "\n";
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -421,7 +402,7 @@ void UnitTest::skip (const std::string& text)
<< mCounter << mCounter
<< " " << " "
<< text << text
<< std::endl; << "\n";
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View file

@ -68,10 +68,10 @@ int Context::handleInteractive ()
} }
// TODO Integrate regular task error handling, using Context::debug. // TODO Integrate regular task error handling, using Context::debug.
catch (int e) { std::cout << e << std::endl; } catch (int e) { std::cout << e << "\n"; }
catch (const char* e) { std::cout << e << std::endl; } catch (const char* e) { std::cout << e << "\n"; }
catch (std::string& e) { std::cout << e << std::endl; } catch (std::string& e) { std::cout << e << "\n"; }
catch (...) { std::cout << "Unknown error." << std::endl; } catch (...) { std::cout << "Unknown error.\n"; }
logWrite ("---"); logWrite ("---");