[gnote] Move semantics for rename and set xml
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Move semantics for rename and set xml
- Date: Tue, 19 Apr 2022 20:08:42 +0000 (UTC)
commit 169fc4a8899344acf81cc0c45c8241bf43b10ea7
Author: Aurimas Černius <aurisc4 gmail com>
Date: Tue Apr 19 23:07:36 2022 +0300
Move semantics for rename and set xml
src/dbus/remotecontrol.cpp | 4 ++--
src/note.cpp | 21 ++++++++++-----------
src/note.hpp | 8 ++++----
src/notebase.cpp | 20 ++++++++++----------
src/notebase.hpp | 8 ++++----
src/notemanagerbase.cpp | 2 +-
src/watchers.cpp | 4 ++--
7 files changed, 33 insertions(+), 34 deletions(-)
---
diff --git a/src/dbus/remotecontrol.cpp b/src/dbus/remotecontrol.cpp
index af0cb49f..62c710c2 100644
--- a/src/dbus/remotecontrol.cpp
+++ b/src/dbus/remotecontrol.cpp
@@ -353,7 +353,7 @@ bool RemoteControl::SetNoteContents(const Glib::ustring& uri,
return false;
}
- std::static_pointer_cast<Note>(note)->set_text_content(text_contents);
+ std::static_pointer_cast<Note>(note)->set_text_content(Glib::ustring(text_contents));
return true;
}
@@ -365,7 +365,7 @@ bool RemoteControl::SetNoteContentsXml(const Glib::ustring& uri,
if(!note) {
return false;
}
- note->set_xml_content(xml_contents);
+ note->set_xml_content(Glib::ustring(xml_contents));
return true;
}
diff --git a/src/note.cpp b/src/note.cpp
index dc9b8c83..00af23ee 100644
--- a/src/note.cpp
+++ b/src/note.cpp
@@ -496,16 +496,15 @@ namespace gnote {
}
}
- void Note::set_title(const Glib::ustring & new_title,
- bool from_user_action)
+ void Note::set_title(Glib::ustring && new_title, bool from_user_action)
{
if (m_data.data().title() != new_title) {
if (m_window) {
m_window->set_name(new_title);
}
- Glib::ustring old_title = m_data.data().title();
- m_data.data().title() = new_title;
+ Glib::ustring old_title = std::move(m_data.data().title());
+ m_data.data().title() = std::move(new_title);
if (from_user_action) {
process_rename_link_update(old_title);
@@ -630,24 +629,24 @@ namespace gnote {
}
}
- void Note::rename_without_link_update(const Glib::ustring & newTitle)
+ void Note::rename_without_link_update(Glib::ustring && newTitle)
{
if(data_synchronizer().data().title() != newTitle) {
if(m_window) {
m_window->set_name(newTitle);
}
}
- NoteBase::rename_without_link_update(newTitle);
+ NoteBase::rename_without_link_update(std::move(newTitle));
}
- void Note::set_xml_content(const Glib::ustring & xml)
+ void Note::set_xml_content(Glib::ustring && xml)
{
if (m_buffer) {
m_buffer->set_text("");
- NoteBufferArchiver::deserialize(m_buffer, xml);
+ NoteBufferArchiver::deserialize(m_buffer, std::move(xml));
}
else {
- NoteBase::set_xml_content(xml);
+ NoteBase::set_xml_content(std::move(xml));
}
}
@@ -659,10 +658,10 @@ namespace gnote {
return m_buffer->get_slice(m_buffer->begin(), m_buffer->end());
}
- void Note::set_text_content(const Glib::ustring & text)
+ void Note::set_text_content(Glib::ustring && text)
{
if(m_buffer) {
- m_buffer->set_text(text);
+ m_buffer->set_text(std::move(text));
}
else {
ERR_OUT(_("Setting text content for closed notes not supported"));
diff --git a/src/note.hpp b/src/note.hpp
index 00e87c78..8e213c4a 100644
--- a/src/note.hpp
+++ b/src/note.hpp
@@ -110,11 +110,11 @@ public:
void add_child_widget(Glib::RefPtr<Gtk::TextChildAnchor> && child_anchor, Gtk::Widget *widget);
using NoteBase::set_title;
- virtual void set_title(const Glib::ustring & new_title, bool from_user_action) override;
- virtual void rename_without_link_update(const Glib::ustring & newTitle) override;
- virtual void set_xml_content(const Glib::ustring & xml) override;
+ void set_title(Glib::ustring && new_title, bool from_user_action) override;
+ void rename_without_link_update(Glib::ustring && newTitle) override;
+ void set_xml_content(Glib::ustring && xml) override;
virtual Glib::ustring text_content() override;
- void set_text_content(const Glib::ustring & text);
+ void set_text_content(Glib::ustring && text);
const Glib::RefPtr<NoteTagTable> & get_tag_table();
bool has_buffer() const
diff --git a/src/notebase.cpp b/src/notebase.cpp
index f119a8ae..24fba50e 100644
--- a/src/notebase.cpp
+++ b/src/notebase.cpp
@@ -141,16 +141,16 @@ const Glib::ustring & NoteBase::get_title() const
return data_synchronizer().data().title();
}
-void NoteBase::set_title(const Glib::ustring & new_title)
+void NoteBase::set_title(Glib::ustring && new_title)
{
- set_title(new_title, false);
+ set_title(std::move(new_title), false);
}
-void NoteBase::set_title(const Glib::ustring & new_title, bool from_user_action)
+void NoteBase::set_title(Glib::ustring && new_title, bool from_user_action)
{
if(data_synchronizer().data().title() != new_title) {
- Glib::ustring old_title = data_synchronizer().data().title();
- data_synchronizer().data().title() = new_title;
+ Glib::ustring old_title = std::move(data_synchronizer().data().title());
+ data_synchronizer().data().title() = std::move(new_title);
if(from_user_action) {
process_rename_link_update(old_title);
@@ -177,13 +177,13 @@ void NoteBase::process_rename_link_update(const Glib::ustring & old_title)
queue_save(CONTENT_CHANGED);
}
-void NoteBase::rename_without_link_update(const Glib::ustring & newTitle)
+void NoteBase::rename_without_link_update(Glib::ustring && newTitle)
{
if(data_synchronizer().data().title() != newTitle) {
- data_synchronizer().data().title() = newTitle;
+ data_synchronizer().data().title() = std::move(newTitle);
// HACK:
- signal_renamed(shared_from_this(), newTitle);
+ signal_renamed(shared_from_this(), data_synchronizer().data().title());
queue_save(CONTENT_CHANGED); // TODO: Right place for this?
}
@@ -313,9 +313,9 @@ Glib::ustring NoteBase::get_complete_note_xml()
return m_manager.note_archiver().write_string(data_synchronizer().synchronized_data());
}
-void NoteBase::set_xml_content(const Glib::ustring & xml)
+void NoteBase::set_xml_content(Glib::ustring && xml)
{
- data_synchronizer().set_text(Glib::ustring(xml));
+ data_synchronizer().set_text(std::move(xml));
}
Glib::ustring NoteBase::text_content()
diff --git a/src/notebase.hpp b/src/notebase.hpp
index 233cb373..d37015dd 100644
--- a/src/notebase.hpp
+++ b/src/notebase.hpp
@@ -211,9 +211,9 @@ public:
const Glib::ustring & uri() const;
const Glib::ustring id() const;
const Glib::ustring & get_title() const;
- void set_title(const Glib::ustring & new_title);
- virtual void set_title(const Glib::ustring & new_title, bool from_user_action);
- virtual void rename_without_link_update(const Glib::ustring & newTitle);
+ void set_title(Glib::ustring && new_title);
+ virtual void set_title(Glib::ustring && new_title, bool from_user_action);
+ virtual void rename_without_link_update(Glib::ustring && newTitle);
virtual void queue_save(ChangeType c);
virtual void save();
@@ -234,7 +234,7 @@ public:
{
return data_synchronizer().text();
}
- virtual void set_xml_content(const Glib::ustring & xml);
+ virtual void set_xml_content(Glib::ustring && xml);
virtual Glib::ustring text_content();
void load_foreign_note_xml(const Glib::ustring & foreignNoteXml, ChangeType changeType);
std::vector<Tag::Ptr> get_tags() const;
diff --git a/src/notemanagerbase.cpp b/src/notemanagerbase.cpp
index acb88147..1927679c 100644
--- a/src/notemanagerbase.cpp
+++ b/src/notemanagerbase.cpp
@@ -334,7 +334,7 @@ NoteBase::Ptr NoteManagerBase::create_new_note(const Glib::ustring & title, cons
if(new_note == 0) {
throw sharp::Exception("Failed to create new note");
}
- new_note->set_xml_content(xml_content);
+ new_note->set_xml_content(Glib::ustring(xml_content));
new_note->signal_renamed.connect(sigc::mem_fun(*this, &NoteManagerBase::on_note_rename));
new_note->signal_saved.connect(sigc::mem_fun(*this, &NoteManagerBase::on_note_save));
diff --git a/src/watchers.cpp b/src/watchers.cpp
index 33559bbc..2252f80b 100644
--- a/src/watchers.cpp
+++ b/src/watchers.cpp
@@ -1,7 +1,7 @@
/*
* gnote
*
- * Copyright (C) 2010-2015,2017,2019-2021 Aurimas Cernius
+ * Copyright (C) 2010-2015,2017,2019-2022 Aurimas Cernius
* Copyright (C) 2010 Debarshi Ray
* Copyright (C) 2009 Hubert Figuiere
*
@@ -215,7 +215,7 @@ namespace gnote {
}
DBG_OUT ("Renaming note from %s to %s", get_note()->get_title().c_str(), title.c_str());
- get_note()->set_title(title, true);
+ get_note()->set_title(std::move(title), true);
return true;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]