Optimize size() and empty() for WaitFreeVector.

This commit is contained in:
levlam 2022-08-03 22:48:18 +03:00
parent bb5d8c0c8d
commit 2be8c86855

View File

@ -53,15 +53,14 @@ class WaitFreeVector {
} }
size_t size() const { size_t size() const {
size_t result = 0; if (storage_.empty()) {
for (auto &storage : storage_) { return 0;
result += storage.size();
} }
return result; return (storage_.size() - 1) * MAX_VECTOR_SIZE + storage_.back().size();
} }
bool empty() const { bool empty() const {
return storage_.empty() || storage_[0].empty(); return storage_.empty();
} }
}; };