about summary refs log tree commit diff homepage
path: root/include/klee/KDAlloc/suballocators/cow_ptr.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/klee/KDAlloc/suballocators/cow_ptr.h')
-rw-r--r--include/klee/KDAlloc/suballocators/cow_ptr.h37
1 files changed, 11 insertions, 26 deletions
diff --git a/include/klee/KDAlloc/suballocators/cow_ptr.h b/include/klee/KDAlloc/suballocators/cow_ptr.h
index 20e12701..ce5957df 100644
--- a/include/klee/KDAlloc/suballocators/cow_ptr.h
+++ b/include/klee/KDAlloc/suballocators/cow_ptr.h
@@ -87,41 +87,26 @@ public:
   /// Accesses an existing object.
   /// Must not be called when `*this` is in an empty state.
   T const &operator*() const noexcept {
-    assert(ptr && "the `CoWPtr` must not be empty");
-    return get();
+    assert(!isEmpty() && "the `CoWPtr` must not be empty");
+    return *get();
   }
 
   /// Accesses an existing object.
   /// Must not be called when `*this` is in an empty state.
   T const *operator->() const noexcept {
-    assert(ptr && "the `CoWPtr` must not be empty");
-    return &get();
-  }
-
-  /// Accesses an existing object.
-  /// Must not be called when `*this` is in an empty state.
-  T const &get() const noexcept {
-    assert(ptr && "the `CoWPtr` must not be empty");
-    return ptr->data;
+    assert(!isEmpty() && "the `CoWPtr` must not be empty");
+    return get();
   }
 
-  /// Accesses an existing, owned object.
-  /// Must not be called when `*this` does not hold CoW ownership.
-  T &getOwned() noexcept {
-    assert(isOwned() && "the `CoWPtr` must be owned");
-    return ptr->data;
-  }
+  /// Gets a pointer to the managed object.
+  /// Returns `nullptr` if no object is currently managed.
+  T const *get() const noexcept { return ptr ? &ptr->data : nullptr; }
 
-  /// Accesses an existing, owned object.
+  /// Gets a pointer to an existing, owned object.
   /// Must not be called when `*this` does not hold CoW ownership.
-  ///
-  /// Note: This function is included for completeness' sake. Instead of calling
-  /// `getOwned` on a constant, one should probably just call `get` as it
-  /// produces the same result without requiring the target object to hold
-  /// ownership of the data.
-  T const &getOwned() const noexcept {
+  T *getOwned() noexcept {
     assert(isOwned() && "the `CoWPtr` must be owned");
-    return ptr->data;
+    return &ptr->data;
   }
 
   /// Acquires CoW ownership of an existing object and returns a reference to
@@ -132,7 +117,7 @@ public:
     assert(ptr->referenceCount > 0);
     if (ptr->referenceCount > 1) {
       --ptr->referenceCount;
-      ptr = new Wrapper(*ptr);
+      ptr = new Wrapper{*ptr};
       ptr->referenceCount = 1;
     }
     assert(ptr->referenceCount == 1);