mirror of
https://github.com/abseil/abseil-cpp.git
synced 2026-06-04 20:14:23 +08:00
Migrate empty CrcCordState to absl::NoDestructor.
Note that this only changes how we allocate the empty state, and reference countings of `empty` stay the same. PiperOrigin-RevId: 599526339 Change-Id: I2c6aaf875c144c947e17fe8f69692b1195b55dd7
This commit is contained in:
committed by
Copybara-Service
parent
fe16a5e72d
commit
49ff696cda
@@ -182,8 +182,8 @@ cc_library(
|
||||
deps = [
|
||||
":crc32c",
|
||||
"//absl/base:config",
|
||||
"//absl/base:no_destructor",
|
||||
"//absl/numeric:bits",
|
||||
"//absl/strings",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@@ -159,6 +159,7 @@ absl_cc_library(
|
||||
absl::crc32c
|
||||
absl::config
|
||||
absl::strings
|
||||
absl::no_destructor
|
||||
)
|
||||
|
||||
absl_cc_test(
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <cassert>
|
||||
|
||||
#include "absl/base/config.h"
|
||||
#include "absl/base/no_destructor.h"
|
||||
#include "absl/numeric/bits.h"
|
||||
|
||||
namespace absl {
|
||||
@@ -24,14 +25,14 @@ ABSL_NAMESPACE_BEGIN
|
||||
namespace crc_internal {
|
||||
|
||||
CrcCordState::RefcountedRep* CrcCordState::RefSharedEmptyRep() {
|
||||
static CrcCordState::RefcountedRep* empty = new CrcCordState::RefcountedRep;
|
||||
static absl::NoDestructor<CrcCordState::RefcountedRep> empty;
|
||||
|
||||
assert(empty->count.load(std::memory_order_relaxed) >= 1);
|
||||
assert(empty->rep.removed_prefix.length == 0);
|
||||
assert(empty->rep.prefix_crc.empty());
|
||||
|
||||
Ref(empty);
|
||||
return empty;
|
||||
Ref(empty.get());
|
||||
return empty.get();
|
||||
}
|
||||
|
||||
CrcCordState::CrcCordState() : refcounted_rep_(new RefcountedRep) {}
|
||||
|
||||
Reference in New Issue
Block a user