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 ())
{
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 ();

View file

@ -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";
}
}

View file

@ -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)

View file

@ -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";
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -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);
}

View file

@ -337,8 +337,7 @@ static std::string importTask_1_4_3 (const std::vector <std::string>& 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 <std::string>& 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 <std::string>& 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 <std::string>& 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 <std::string>& 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 <std::string>& 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 <std::string>& 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 <std::string>& lines)
std::stringstream out;
out << "Imported "
<< count
<< " tasks successfully."
<< std::endl;
<< " tasks successfully.\n";
return out.str ();
}

View file

@ -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;
}

View file

@ -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];

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);
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 ();
}

View file

@ -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";
}
///////////////////////////////////////////////////////////////////////////////

View file

@ -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 ("---");