Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[pvs-studio] Protect from self assignment.
[simgrid.git] / src / mc / sosp / ChunkedData.hpp
index 8d5f1ba..85f0790 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2014-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2014-2021. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -46,7 +46,7 @@ public:
     for (std::size_t const& pageno : pagenos_)
       store_->ref_page(pageno);
   }
-  ChunkedData(ChunkedData&& that) : pagenos_(std::move(that.pagenos_))
+  ChunkedData(ChunkedData&& that) noexcept : pagenos_(std::move(that.pagenos_))
   {
     std::swap(store_, that.store_);
     that.pagenos_.clear();
@@ -62,13 +62,15 @@ public:
     }
     return *this;
   }
-  ChunkedData& operator=(ChunkedData&& that)
+  ChunkedData& operator=(ChunkedData&& that) noexcept
   {
-    this->clear();
-    store_      = that.store_;
-    that.store_ = nullptr;
-    pagenos_    = std::move(that.pagenos_);
-    that.pagenos_.clear();
+    if (this != &that) {
+      this->clear();
+      store_      = that.store_;
+      that.store_ = nullptr;
+      pagenos_    = std::move(that.pagenos_);
+      that.pagenos_.clear();
+    }
     return *this;
   }
 
@@ -81,10 +83,10 @@ public:
   /** Get a view of the chunk indices */
   const std::size_t* pagenos() const { return pagenos_.data(); }
 
-  /** Get a pointer to a chunk */
+  /** Get a pointer to a chunk */
   void* page(std::size_t i) const { return store_->get_page(pagenos_[i]); }
 
-  ChunkedData(PageStore& store, AddressSpace& as, RemotePtr<void> addr, std::size_t page_count);
+  ChunkedData(PageStore& store, const AddressSpace& as, RemotePtr<void> addr, std::size_t page_count);
 };
 
 } // namespace mc