Merge branch 'google:main' into main

This commit is contained in:
Sergey Romanenko 2025-02-24 23:17:06 +03:00 committed by GitHub
commit d22d0929d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 13 deletions

View File

@ -874,9 +874,13 @@ class SingletonEnv {
#endif // !defined(NDEBUG)
static_assert(sizeof(env_storage_) >= sizeof(EnvType),
"env_storage_ will not fit the Env");
static_assert(alignof(decltype(env_storage_)) >= alignof(EnvType),
static_assert(std::is_standard_layout_v<SingletonEnv<EnvType>>);
static_assert(
offsetof(SingletonEnv<EnvType>, env_storage_) % alignof(EnvType) == 0,
"env_storage_ does not meet the Env's alignment needs");
new (&env_storage_) EnvType();
static_assert(alignof(SingletonEnv<EnvType>) % alignof(EnvType) == 0,
"env_storage_ does not meet the Env's alignment needs");
new (env_storage_) EnvType();
}
~SingletonEnv() = default;
@ -892,8 +896,7 @@ class SingletonEnv {
}
private:
typename std::aligned_storage<sizeof(EnvType), alignof(EnvType)>::type
env_storage_;
alignas(EnvType) char env_storage_[sizeof(EnvType)];
#if !defined(NDEBUG)
static std::atomic<bool> env_initialized_;
#endif // !defined(NDEBUG)

View File

@ -769,9 +769,13 @@ class SingletonEnv {
#endif // !defined(NDEBUG)
static_assert(sizeof(env_storage_) >= sizeof(EnvType),
"env_storage_ will not fit the Env");
static_assert(alignof(decltype(env_storage_)) >= alignof(EnvType),
static_assert(std::is_standard_layout_v<SingletonEnv<EnvType>>);
static_assert(
offsetof(SingletonEnv<EnvType>, env_storage_) % alignof(EnvType) == 0,
"env_storage_ does not meet the Env's alignment needs");
new (&env_storage_) EnvType();
static_assert(alignof(SingletonEnv<EnvType>) % alignof(EnvType) == 0,
"env_storage_ does not meet the Env's alignment needs");
new (env_storage_) EnvType();
}
~SingletonEnv() = default;
@ -787,8 +791,7 @@ class SingletonEnv {
}
private:
typename std::aligned_storage<sizeof(EnvType), alignof(EnvType)>::type
env_storage_;
alignas(EnvType) char env_storage_[sizeof(EnvType)];
#if !defined(NDEBUG)
static std::atomic<bool> env_initialized_;
#endif // !defined(NDEBUG)

View File

@ -27,7 +27,7 @@ uint32_t Hash(const char* data, size_t n, uint32_t seed) {
uint32_t h = seed ^ (n * m);
// Pick up four bytes at a time
while (data + 4 <= limit) {
while (limit - data >= 4) {
uint32_t w = DecodeFixed32(data);
data += 4;
h += w;

View File

@ -5,6 +5,7 @@
#ifndef STORAGE_LEVELDB_UTIL_NO_DESTRUCTOR_H_
#define STORAGE_LEVELDB_UTIL_NO_DESTRUCTOR_H_
#include <cstddef>
#include <type_traits>
#include <utility>
@ -20,10 +21,14 @@ class NoDestructor {
explicit NoDestructor(ConstructorArgTypes&&... constructor_args) {
static_assert(sizeof(instance_storage_) >= sizeof(InstanceType),
"instance_storage_ is not large enough to hold the instance");
static_assert(std::is_standard_layout_v<NoDestructor<InstanceType>>);
static_assert(
alignof(decltype(instance_storage_)) >= alignof(InstanceType),
offsetof(NoDestructor, instance_storage_) % alignof(InstanceType) == 0,
"instance_storage_ does not meet the instance's alignment requirement");
new (&instance_storage_)
static_assert(
alignof(NoDestructor<InstanceType>) % alignof(InstanceType) == 0,
"instance_storage_ does not meet the instance's alignment requirement");
new (instance_storage_)
InstanceType(std::forward<ConstructorArgTypes>(constructor_args)...);
}
@ -37,8 +42,7 @@ class NoDestructor {
}
private:
typename std::aligned_storage<sizeof(InstanceType),
alignof(InstanceType)>::type instance_storage_;
alignas(InstanceType) char instance_storage_[sizeof(InstanceType)];
};
} // namespace leveldb