[gnote] Replace list with vector for get_tags
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Replace list with vector for get_tags
- Date: Sat, 13 Apr 2019 17:36:57 +0000 (UTC)
commit e3ee96504ad982a75b4ce17608e38379bdb5e166
Author: Aurimas Černius <aurisc4 gmail com>
Date: Sat Apr 13 19:46:24 2019 +0300
Replace list with vector for get_tags
src/dbus/remotecontrol.cpp | 8 +++-----
src/notebase.cpp | 9 +++++----
src/notebase.hpp | 2 +-
src/notebooks/notebookmanager.cpp | 8 +++-----
src/searchnoteswidget.cpp | 8 +++-----
src/watchers.cpp | 3 +--
6 files changed, 16 insertions(+), 22 deletions(-)
---
diff --git a/src/dbus/remotecontrol.cpp b/src/dbus/remotecontrol.cpp
index c6c5ae66..6f836b63 100644
--- a/src/dbus/remotecontrol.cpp
+++ b/src/dbus/remotecontrol.cpp
@@ -242,11 +242,9 @@ namespace gnote {
return std::vector<Glib::ustring>();
std::vector<Glib::ustring> tags;
- std::list<Tag::Ptr> l;
- note->get_tags(l);
- for (std::list<Tag::Ptr>::const_iterator iter = l.begin();
- iter != l.end(); ++iter) {
- tags.push_back((*iter)->normalized_name());
+ std::vector<Tag::Ptr> l = note->get_tags();
+ for(auto & tag : l) {
+ tags.push_back(tag->normalized_name());
}
return tags;
}
diff --git a/src/notebase.cpp b/src/notebase.cpp
index d9d0ea98..63adf163 100644
--- a/src/notebase.cpp
+++ b/src/notebase.cpp
@@ -309,7 +309,7 @@ void NoteBase::load_foreign_note_xml(const Glib::ustring & foreignNoteXml, Chang
// Remove tags now, since a note with no tags has
// no "tags" element in the XML
- std::list<Tag::Ptr> new_tags;
+ std::vector<Tag::Ptr> new_tags;
Glib::ustring name;
while(xml.read()) {
@@ -353,8 +353,7 @@ void NoteBase::load_foreign_note_xml(const Glib::ustring & foreignNoteXml, Chang
xml.close();
- std::list<Tag::Ptr> tag_list;
- get_tags(tag_list);
+ std::vector<Tag::Ptr> tag_list = get_tags();
for(Tag::Ptr & iter : tag_list) {
if(std::find(new_tags.begin(), new_tags.end(), iter) == new_tags.end()) {
@@ -369,9 +368,11 @@ void NoteBase::load_foreign_note_xml(const Glib::ustring & foreignNoteXml, Chang
queue_save(changeType);
}
-void NoteBase::get_tags(std::list<Tag::Ptr> & l) const
+std::vector<Tag::Ptr> NoteBase::get_tags() const
{
+ std::list<Tag::Ptr> l;
sharp::map_get_values(data_synchronizer().data().tags(), l);
+ return std::vector<Tag::Ptr>(l.begin(), l.end());
}
const NoteData & NoteBase::data() const
diff --git a/src/notebase.hpp b/src/notebase.hpp
index 9c10eb69..d80b0134 100644
--- a/src/notebase.hpp
+++ b/src/notebase.hpp
@@ -235,7 +235,7 @@ public:
}
virtual void set_xml_content(const Glib::ustring & xml);
void load_foreign_note_xml(const Glib::ustring & foreignNoteXml, ChangeType changeType);
- void get_tags(std::list<Tag::Ptr> &) const;
+ std::vector<Tag::Ptr> get_tags() const;
const NoteData & data() const;
NoteData & data();
diff --git a/src/notebooks/notebookmanager.cpp b/src/notebooks/notebookmanager.cpp
index b6dd2209..925ee6ca 100644
--- a/src/notebooks/notebookmanager.cpp
+++ b/src/notebooks/notebookmanager.cpp
@@ -246,11 +246,9 @@ namespace gnote {
/// </returns>
Notebook::Ptr NotebookManager::get_notebook_from_note(const NoteBase::Ptr & note)
{
- std::list<Tag::Ptr> tags;
- note->get_tags(tags);
- for(std::list<Tag::Ptr>::const_iterator iter = tags.begin();
- iter != tags.end(); ++iter) {
- Notebook::Ptr notebook = get_notebook_from_tag (*iter);
+ std::vector<Tag::Ptr> tags = note->get_tags();
+ for(auto & tag : tags) {
+ Notebook::Ptr notebook = get_notebook_from_tag(tag);
if (notebook)
return notebook;
}
diff --git a/src/searchnoteswidget.cpp b/src/searchnoteswidget.cpp
index 802006a4..23853945 100644
--- a/src/searchnoteswidget.cpp
+++ b/src/searchnoteswidget.cpp
@@ -779,11 +779,9 @@ bool SearchNotesWidget::filter_by_tag(const Note::Ptr & note)
}
// // FIXME: Ugh! NOT an O(1) operation. Is there a better way?
- std::list<Tag::Ptr> tags;
- note->get_tags(tags);
- for(std::list<Tag::Ptr>::const_iterator iter = tags.begin();
- iter != tags.end(); ++iter) {
- if(m_selected_tags.find(*iter) != m_selected_tags.end()) {
+ std::vector<Tag::Ptr> tags = note->get_tags();
+ for(auto & tag : tags) {
+ if(m_selected_tags.find(tag) != m_selected_tags.end()) {
return true;
}
}
diff --git a/src/watchers.cpp b/src/watchers.cpp
index 8300a27e..83c60558 100644
--- a/src/watchers.cpp
+++ b/src/watchers.cpp
@@ -447,8 +447,7 @@ namespace gnote {
Tag::Ptr NoteSpellChecker::get_language_tag()
{
Tag::Ptr lang_tag;
- std::list<Tag::Ptr> tags;
- get_note()->get_tags(tags);
+ std::vector<Tag::Ptr> tags = get_note()->get_tags();
for(Tag::Ptr tag : tags) {
if(tag->name().find(LANG_PREFIX) == 0) {
lang_tag = tag;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]