Skip to content

Commit e998d43

Browse files
drymancopybara-github
authored andcommitted
Remove move ctor/assignment from TriStatePtr::SharedRef
Moving TriStatePtr::SharedRef is error prone to get the refcount right. While it is possible to implement one, the use case is so rare to justify. PiperOrigin-RevId: 713667208
1 parent 1f72e6d commit e998d43

1 file changed

Lines changed: 2 additions & 15 deletions

File tree

cpp/tri_state_ptr.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ class TriStatePtr {
8484
&state_));
8585
}
8686

87-
// explicit TriStatePtr(std::unique_ptr<BaseT> ptr) : ptr_(std::move(ptr)) {}
8887
explicit TriStatePtr(std::unique_ptr<BaseT> ptr) : ptr_(std::move(ptr)) {}
8988

9089
class SharedRef {
@@ -95,24 +94,12 @@ class TriStatePtr {
9594
parent_->ref_count_++;
9695
}
9796
SharedRef& operator=(const SharedRef& other) {
98-
this->parent_ = other.parent_;
99-
this->parent_->ref_count_++;
100-
return *this;
101-
}
102-
103-
SharedRef(SharedRef&& other) : parent_(other.parent_) {
104-
other.parent_ = nullptr;
105-
}
106-
SharedRef& operator=(SharedRef&& other) {
107-
this->parent_ = other.parent_;
108-
other.parent_ = nullptr;
97+
parent_ = other.parent_;
98+
parent_->ref_count_++;
10999
return *this;
110100
}
111101

112102
~SharedRef() {
113-
if (parent_ == nullptr) {
114-
return;
115-
}
116103
int32_t ref_count =
117104
parent_->ref_count_.fetch_sub(1, std::memory_order_acq_rel) - 1;
118105
if (ref_count == 0) {

0 commit comments

Comments
 (0)