[gnote] A set of move semantics for Note



commit f548bb9e4071372cc4ce27a6c48db28e97a3388d
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Mon Apr 18 22:57:41 2022 +0300

    A set of move semantics for Note

 src/note.cpp                 | 21 +++++++++------------
 src/note.hpp                 | 14 ++++----------
 src/notemanager.cpp          | 10 +++++-----
 src/notemanager.hpp          |  4 ++--
 src/notemanagerbase.cpp      |  4 ++--
 src/notemanagerbase.hpp      |  4 ++--
 src/test/testnotemanager.cpp |  4 ++--
 src/test/testnotemanager.hpp |  4 ++--
 8 files changed, 28 insertions(+), 37 deletions(-)
---
diff --git a/src/note.cpp b/src/note.cpp
index d0e9b199..64ce710e 100644
--- a/src/note.cpp
+++ b/src/note.cpp
@@ -246,8 +246,8 @@ namespace gnote {
     }
   }
 
-  Note::Note(std::unique_ptr<NoteData> _data, const Glib::ustring & filepath, NoteManager & _manager, IGnote 
& g)
-    : NoteBase(filepath, _manager)
+  Note::Note(std::unique_ptr<NoteData> _data, Glib::ustring && filepath, NoteManager & _manager, IGnote & g)
+    : NoteBase(std::move(filepath), _manager)
     , m_gnote(g)
     , m_data(std::move(_data))
     , m_save_needed(false)
@@ -270,21 +270,18 @@ namespace gnote {
     delete m_window;
   }
 
-  Note::Ptr Note::create_new_note(const Glib::ustring & title,
-                                  const Glib::ustring & filename,
-                                  NoteManager & manager,
-                                  IGnote & g)
+  Note::Ptr Note::create_new_note(Glib::ustring && title, Glib::ustring && filename, NoteManager & manager, 
IGnote & g)
   {
     auto note_data = std::make_unique<NoteData>(url_from_path(filename));
-    note_data->title() = title;
+    note_data->title() = std::move(title);
     auto date(Glib::DateTime::create_now_local());
     note_data->create_date() = date;
     note_data->set_change_date(date);
       
-    return std::make_shared<Note>(std::move(note_data), filename, manager, g);
+    return std::make_shared<Note>(std::move(note_data), std::move(filename), manager, g);
   }
 
-  Note::Ptr Note::create_existing_note(std::unique_ptr<NoteData> data, Glib::ustring filepath, NoteManager & 
manager, IGnote & g)
+  Note::Ptr Note::create_existing_note(std::unique_ptr<NoteData> data, Glib::ustring && filepath, 
NoteManager & manager, IGnote & g)
   {
     if (!data->change_date()) {
       auto d(sharp::file_modification_time(filepath));
@@ -299,7 +296,7 @@ namespace gnote {
         data->create_date() = d;
       }
     }
-    return std::make_shared<Note>(std::move(data), filepath, manager, g);
+    return std::make_shared<Note>(std::move(data), std::move(filepath), manager, g);
   }
 
   void Note::delete_note()
@@ -326,11 +323,11 @@ namespace gnote {
   }
 
   
-  Note::Ptr Note::load(const Glib::ustring & read_file, NoteManager & manager, IGnote & g)
+  Note::Ptr Note::load(Glib::ustring && read_file, NoteManager & manager, IGnote & g)
   {
     auto data = std::make_unique<NoteData>(url_from_path(read_file));
     manager.note_archiver().read_file(read_file, *data);
-    return create_existing_note(std::move(data), read_file, manager, g);
+    return create_existing_note(std::move(data), std::move(read_file), manager, g);
   }
 
   
diff --git a/src/note.hpp b/src/note.hpp
index 96351670..5b925400 100644
--- a/src/note.hpp
+++ b/src/note.hpp
@@ -96,19 +96,13 @@ public:
   ~Note();
 
 
-  static Note::Ptr create_new_note(const Glib::ustring & title,
-                                   const Glib::ustring & filename,
-                                   NoteManager & manager,
-                                   IGnote & g);
+  static Note::Ptr create_new_note(Glib::ustring && title, Glib::ustring && filename, NoteManager & manager, 
IGnote & g);
 
-  static Note::Ptr create_existing_note(std::unique_ptr<NoteData> data,
-                                        Glib::ustring filepath,
-                                        NoteManager & manager,
-                                        IGnote & g);
+  static Note::Ptr create_existing_note(std::unique_ptr<NoteData> data, Glib::ustring && filepath, 
NoteManager & manager, IGnote & g);
 
-  Note(std::unique_ptr<NoteData> _data, const Glib::ustring & filepath, NoteManager & manager, IGnote & g);
+  Note(std::unique_ptr<NoteData> _data, Glib::ustring && filepath, NoteManager & manager, IGnote & g);
   virtual void delete_note() override;
-  static Note::Ptr load(const Glib::ustring &, NoteManager &, IGnote &);
+  static Note::Ptr load(Glib::ustring &&, NoteManager &, IGnote &);
   virtual void save() override;
   virtual void queue_save(ChangeType c) override;
   using NoteBase::remove_tag;
diff --git a/src/notemanager.cpp b/src/notemanager.cpp
index 5dda9c96..0cad04f4 100644
--- a/src/notemanager.cpp
+++ b/src/notemanager.cpp
@@ -163,9 +163,9 @@ namespace gnote {
   {
     std::vector<Glib::ustring> files = sharp::directory_get_files_with_ext(notes_dir(), ".note");
 
-    for(auto file_path : files) {
+    for(auto & file_path : files) {
       try {
-        Note::Ptr note = Note::load(file_path, *this, m_gnote);
+        Note::Ptr note = Note::load(std::move(file_path), *this, m_gnote);
         add_note(note);
       } 
       catch (const std::exception & e) {
@@ -249,9 +249,9 @@ namespace gnote {
     }
   }
 
-  NoteBase::Ptr NoteManager::note_load(const Glib::ustring & file_name)
+  NoteBase::Ptr NoteManager::note_load(Glib::ustring && file_name)
   {
-    return Note::load(file_name, *this, m_gnote);
+    return Note::load(std::move(file_name), *this, m_gnote);
   }
 
 
@@ -280,7 +280,7 @@ namespace gnote {
 
   NoteBase::Ptr NoteManager::note_create_new(const Glib::ustring & title, const Glib::ustring & file_name)
   {
-    return Note::create_new_note(title, file_name, *this, m_gnote);
+    return Note::create_new_note(Glib::ustring(title), Glib::ustring(file_name), *this, m_gnote);
   }
 
   NoteBase::Ptr NoteManager::get_or_create_template_note()
diff --git a/src/notemanager.hpp b/src/notemanager.hpp
index a9ad21a2..fc3cd731 100644
--- a/src/notemanager.hpp
+++ b/src/notemanager.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2014,2017,2019-2020 Aurimas Cernius
+ * Copyright (C) 2010-2014,2017,2019-2020,2022 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -81,7 +81,7 @@ namespace gnote {
     virtual NoteBase::Ptr create_new_note(const Glib::ustring & title, const Glib::ustring & xml_content,
                                           const Glib::ustring & guid) override;
     virtual NoteBase::Ptr note_create_new(const Glib::ustring & title, const Glib::ustring & file_name) 
override;
-    virtual NoteBase::Ptr note_load(const Glib::ustring & file_name) override;
+    NoteBase::Ptr note_load(Glib::ustring && file_name) override;
   private:
     AddinManager *create_addin_manager();
     void create_start_notes();
diff --git a/src/notemanagerbase.cpp b/src/notemanagerbase.cpp
index 63eefa06..acb88147 100644
--- a/src/notemanagerbase.cpp
+++ b/src/notemanagerbase.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2014,2016-2017,2019-2021 Aurimas Cernius
+ * Copyright (C) 2010-2014,2016-2017,2019-2022 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -486,7 +486,7 @@ NoteBase::Ptr NoteManagerBase::import_note(const Glib::ustring & file_path)
     sharp::file_copy(file_path, dest_file);
 
     // TODO: make sure the title IS unique.
-    note = note_load(dest_file);
+    note = note_load(std::move(dest_file));
     add_note(note);
   }
   catch(...)
diff --git a/src/notemanagerbase.hpp b/src/notemanagerbase.hpp
index 0ef31dc7..b7a9875b 100644
--- a/src/notemanagerbase.hpp
+++ b/src/notemanagerbase.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2014,2017,2019-2020 Aurimas Cernius
+ * Copyright (C) 2010-2014,2017,2019-2020,2022 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -113,7 +113,7 @@ protected:
   virtual NoteBase::Ptr note_create_new(const Glib::ustring & title, const Glib::ustring & file_name) = 0;
   Glib::ustring make_new_file_name() const;
   Glib::ustring make_new_file_name(const Glib::ustring & guid) const;
-  virtual NoteBase::Ptr note_load(const Glib::ustring & file_name) = 0;
+  virtual NoteBase::Ptr note_load(Glib::ustring && file_name) = 0;
 
   IGnote & m_gnote;
   NoteBase::List m_notes;
diff --git a/src/test/testnotemanager.cpp b/src/test/testnotemanager.cpp
index ff580b2e..be03dac3 100644
--- a/src/test/testnotemanager.cpp
+++ b/src/test/testnotemanager.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2014,2017,2019-2020 Aurimas Cernius
+ * Copyright (C) 2014,2017,2019-2020,2022 Aurimas Cernius
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -60,7 +60,7 @@ gnote::NoteBase::Ptr NoteManager::note_create_new(const Glib::ustring & title, c
   return std::make_shared<Note>(std::move(note_data), file_name, *this);
 }
 
-gnote::NoteBase::Ptr NoteManager::note_load(const Glib::ustring & /*file_name*/)
+gnote::NoteBase::Ptr NoteManager::note_load(Glib::ustring && /*file_name*/)
 {
   return gnote::NoteBase::Ptr();
 }
diff --git a/src/test/testnotemanager.hpp b/src/test/testnotemanager.hpp
index f6002f3f..d05374d0 100644
--- a/src/test/testnotemanager.hpp
+++ b/src/test/testnotemanager.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2014,2019-2020 Aurimas Cernius
+ * Copyright (C) 2014,2019-2020,2022 Aurimas Cernius
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -52,7 +52,7 @@ public:
     }
 protected:
   virtual gnote::NoteBase::Ptr note_create_new(const Glib::ustring & title, const Glib::ustring & file_name) 
override;
-  virtual gnote::NoteBase::Ptr note_load(const Glib::ustring & file_name) override;
+  gnote::NoteBase::Ptr note_load(Glib::ustring && file_name) override;
 private:
   gnote::notebooks::NotebookManager m_notebook_manager;
   gnote::NoteArchiver m_note_archiver;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]