[gnote] Simplified the fix for GNOME Bugzilla #605869
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Simplified the fix for GNOME Bugzilla #605869
- Date: Thu, 11 Mar 2010 23:28:22 +0000 (UTC)
commit 85403e104467f2b18640ebb277203d0ab5875bbb
Author: Daniel Elstner <daniel kitta gmail com>
Date: Fri Mar 12 00:51:10 2010 +0200
Simplified the fix for GNOME Bugzilla #605869
+ Going through the exception was inappropriate here, as not finding
the '\n' is a perfectly normal condition you may as well just handle
directly.
+ Initializing an std::string with "" to create an empty string
needlessly allocates storage and copies the empty string to it. You
can just use the default constructor instead.
+ Calling std::string::find() with a string literal to perform a
substring search is unnecessarily expensive compared to a simple
character search.
src/addins/noteoftheday/noteoftheday.cpp | 12 +++++-------
1 files changed, 5 insertions(+), 7 deletions(-)
---
diff --git a/src/addins/noteoftheday/noteoftheday.cpp b/src/addins/noteoftheday/noteoftheday.cpp
index b6efca7..030cc3f 100644
--- a/src/addins/noteoftheday/noteoftheday.cpp
+++ b/src/addins/noteoftheday/noteoftheday.cpp
@@ -113,14 +113,12 @@ std::string NoteOfTheDay::get_content(
std::string NoteOfTheDay::get_content_without_title(
const std::string & content)
{
- std::string str = "";
- try {
- str = content.substr(content.find("\n", 0), std::string::npos);
- }
- catch (const std::exception &) {
- }
+ const std::string::size_type nl = content.find("\n");
- return str;
+ if (std::string::npos != nl)
+ return std::string(content, nl, std::string::npos);
+ else
+ return std::string();
}
gnote::Note::Ptr NoteOfTheDay::get_note_by_date(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]