[gnote] Move semantics for Tag



commit 6e442e0ecb9cc878f7f4f8576a6edb1ea9688a9d
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun Jun 19 18:01:38 2022 +0300

    Move semantics for Tag

 src/tag.cpp                 | 10 +++++-----
 src/tag.hpp                 |  6 +++---
 src/tagmanager.cpp          |  4 ++--
 src/test/testtagmanager.cpp |  4 ++--
 4 files changed, 12 insertions(+), 12 deletions(-)
---
diff --git a/src/tag.cpp b/src/tag.cpp
index 83693b5d..e97b2fe5 100644
--- a/src/tag.cpp
+++ b/src/tag.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2014,2017,2019 Aurimas Cernius
+ * Copyright (C) 2014,2017,2019,2022 Aurimas Cernius
  * Copyright (C) 2010 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -34,11 +34,11 @@ namespace gnote {
 
   const char * Tag::SYSTEM_TAG_PREFIX = "system:";
 
-  Tag::Tag(const Glib::ustring & _name)
+  Tag::Tag(Glib::ustring && _name)
     : m_issystem(false)
     , m_isproperty(false)
   {
-    set_name(_name);
+    set_name(std::move(_name));
   }
 
   void Tag::add_note(NoteBase & note)
@@ -58,13 +58,13 @@ namespace gnote {
   }
 
 
-  void Tag::set_name(const Glib::ustring & value)
+  void Tag::set_name(Glib::ustring && value)
   {
     if (!value.empty()) {
       Glib::ustring trimmed_name = sharp::string_trim(value);
       if (!trimmed_name.empty()) {
-        m_name = trimmed_name;
         m_normalized_name = trimmed_name.lowercase();
+        m_name = std::move(trimmed_name);
         if(Glib::str_has_prefix(m_normalized_name, SYSTEM_TAG_PREFIX)) {
           m_issystem = true;
         }
diff --git a/src/tag.hpp b/src/tag.hpp
index d204d21f..3cae1d49 100644
--- a/src/tag.hpp
+++ b/src/tag.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2013-2014,2017,2019 Aurimas Cernius
+ * Copyright (C) 2013-2014,2017,2019,2022 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -47,7 +47,7 @@ namespace gnote {
     typedef std::shared_ptr<Tag> Ptr;
     static const char * SYSTEM_TAG_PREFIX;
 
-    Tag(const Glib::ustring & name);
+    Tag(Glib::ustring && name);
 
     // <summary>
     // Associates the specified note with this tag.
@@ -65,7 +65,7 @@ namespace gnote {
       {
         return m_name;
       }
-    void set_name(const Glib::ustring & );
+    void set_name(Glib::ustring && name);
     // <summary>
     // Use the string returned here to reference the tag in Dictionaries.
     // </summary>
diff --git a/src/tagmanager.cpp b/src/tagmanager.cpp
index 3b833676..4b8937e5 100644
--- a/src/tagmanager.cpp
+++ b/src/tagmanager.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011,2013-2014,2017,2019,2021 Aurimas Cernius
+ * Copyright (C) 2011,2013-2014,2017,2019,2021-2022 Aurimas Cernius
  * Copyright (C) 2010 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -111,7 +111,7 @@ namespace gnote {
         return iter->second;
       }
       else {
-        Tag::Ptr t(std::make_shared<Tag>(tag_name));
+        Tag::Ptr t(std::make_shared<Tag>(Glib::ustring(tag_name)));
         m_internal_tags [ t->normalized_name() ] = t;
         return t;
       }
diff --git a/src/test/testtagmanager.cpp b/src/test/testtagmanager.cpp
index 7b5d0e3d..541b8b3b 100644
--- a/src/test/testtagmanager.cpp
+++ b/src/test/testtagmanager.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2014,2017-2020 Aurimas Cernius
+ * Copyright (C) 2014,2017-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
@@ -37,7 +37,7 @@ gnote::Tag::Ptr TagManager::get_or_create_tag(const Glib::ustring & tag_name)
   if(iter != m_tags.end()) {
     return iter->second;
   }
-  gnote::Tag::Ptr tag = gnote::Tag::Ptr(new gnote::Tag(tag_name));
+  gnote::Tag::Ptr tag = gnote::Tag::Ptr(new gnote::Tag(Glib::ustring(tag_name)));
   m_tags[tag_name] = tag;
   return tag;
 }


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