Export of internal Abseil changes.

--
dcff7cc4eb3837d39d1e083cbf1d4f082054cbf6 by Laramie Leavitt <lar@google.com>:

Add default and fallback modes for SaltedSeedSeq::generate().

SeedSeq::generate will often be called with contiguous ranges of uint32_t.
Detect this case and use the currently direct code paths to handle it.
Otherwise use a fallback mechanism which does an additional copy.
PiperOrigin-RevId: 258853656

--
59ec88845ac2ee6567c493021b54385940d66762 by Gennadiy Rozental <rogeeff@google.com>:

Internal change

PiperOrigin-RevId: 258822137

--
eb2d1ab21f6f94c24c51c1cd3719846be259e8e7 by Abseil Team <absl-team@google.com>:

Add iOS version 11 to the mix of Apple OS versions that have various C++17 header files
but do not support them.

PiperOrigin-RevId: 258820405

--
452cea3e13b29797b2c385d7c6da7613d36bdc45 by Gennadiy Rozental <rogeeff@google.com>:

Internal change

PiperOrigin-RevId: 258802436
GitOrigin-RevId: dcff7cc4eb3837d39d1e083cbf1d4f082054cbf6
Change-Id: I2261cb58e142eb15017ef646a56710dd64f06496
This commit is contained in:
Abseil Team 2019-07-18 15:07:49 -07:00 committed by Derek Mauro
parent 278b26058c
commit f3840bc5e3
5 changed files with 67 additions and 122 deletions

View file

@ -216,17 +216,16 @@ void SetFlag(absl::Flag<T>* flag, const V& v) {
// Note: Name of registrar object is not arbitrary. It is used to "grab"
// global name for FLAGS_no<flag_name> symbol, thus preventing the possibility
// of defining two flags with names foo and nofoo.
#define ABSL_FLAG_IMPL(Type, name, default_value, help) \
namespace absl {} \
ABSL_FLAG_IMPL_DECLARE_DEF_VAL_WRAPPER(name, Type, default_value) \
ABSL_FLAG_IMPL_DECLARE_HELP_WRAPPER(name, help) \
absl::Flag<Type> FLAGS_##name( \
ABSL_FLAG_IMPL_FLAGNAME(#name), \
&AbslFlagsWrapHelp##name, \
ABSL_FLAG_IMPL_FILENAME(), \
&absl::flags_internal::FlagMarshallingOps<Type>, \
&AbslFlagsInitFlag##name); \
extern bool FLAGS_no##name; \
#define ABSL_FLAG_IMPL(Type, name, default_value, help) \
namespace absl {} \
ABSL_FLAG_IMPL_DECLARE_DEF_VAL_WRAPPER(name, Type, default_value) \
ABSL_FLAG_IMPL_DECLARE_HELP_WRAPPER(name, help) \
ABSL_CONST_INIT absl::Flag<Type> FLAGS_##name( \
ABSL_FLAG_IMPL_FLAGNAME(#name), &AbslFlagsWrapHelp##name, \
ABSL_FLAG_IMPL_FILENAME(), \
&absl::flags_internal::FlagMarshallingOps<Type>, \
&AbslFlagsInitFlag##name); \
extern bool FLAGS_no##name; \
bool FLAGS_no##name = ABSL_FLAG_IMPL_REGISTRAR(Type, FLAGS_##name)
// ABSL_RETIRED_FLAG

View file

@ -54,53 +54,6 @@ void DestroyFlag(CommandLineFlag* flag) NO_THREAD_SAFETY_ANALYSIS {
// the function will acquire it itself if needed.
// --------------------------------------------------------------------
// A map from flag pointer to CommandLineFlag*. Used when registering
// validators.
class FlagPtrMap {
public:
void Register(CommandLineFlag* flag) {
auto& vec = buckets_[BucketForFlag(flag->cur)];
if (vec.size() == vec.capacity()) {
// Bypass default 2x growth factor with 1.25 so we have fuller vectors.
// This saves 4% memory compared to default growth.
vec.reserve(vec.size() * 1.25 + 0.5);
}
vec.push_back(flag);
}
CommandLineFlag* FindByPtr(const void* flag_ptr) {
const auto& flag_vector = buckets_[BucketForFlag(flag_ptr)];
for (CommandLineFlag* entry : flag_vector) {
if (entry->cur == flag_ptr) {
return entry;
}
}
return nullptr;
}
private:
// Instead of std::map, we use a custom hash table where each bucket stores
// flags in a vector. This reduces memory usage 40% of the memory that would
// have been used by std::map.
//
// kNumBuckets was picked as a large enough prime. As of writing this code, a
// typical large binary has ~8k (old-style) flags, and this would gives
// buckets with roughly 50 elements each.
//
// Note that reads to this hash table are rare: exactly as many as we have
// flags with validators. As of writing, a typical binary only registers 52
// validated flags.
static constexpr size_t kNumBuckets = 163;
std::vector<CommandLineFlag*> buckets_[kNumBuckets];
static int BucketForFlag(const void* ptr) {
// Modulo a prime is good enough here. On a real program, bucket size stddev
// after registering 8k flags is ~5 (mean size at 51).
return reinterpret_cast<uintptr_t>(ptr) % kNumBuckets;
}
};
constexpr size_t FlagPtrMap::kNumBuckets;
class FlagRegistry {
public:
FlagRegistry() = default;
@ -111,9 +64,7 @@ class FlagRegistry {
}
// Store a flag in this registry. Takes ownership of *flag.
// If ptr is non-null, the flag can later be found by calling
// FindFlagViaPtrLocked(ptr).
void RegisterFlag(CommandLineFlag* flag, const void* ptr);
void RegisterFlag(CommandLineFlag* flag);
void Lock() EXCLUSIVE_LOCK_FUNCTION(lock_) { lock_.Lock(); }
void Unlock() UNLOCK_FUNCTION(lock_) { lock_.Unlock(); }
@ -126,9 +77,6 @@ class FlagRegistry {
// found or not retired. Does not emit a warning.
CommandLineFlag* FindRetiredFlagLocked(absl::string_view name);
// Returns the flag object whose current-value is stored at flag_ptr.
CommandLineFlag* FindFlagViaPtrLocked(const void* flag_ptr);
static FlagRegistry* GlobalRegistry(); // returns a singleton registry
private:
@ -142,8 +90,6 @@ class FlagRegistry {
using FlagConstIterator = FlagMap::const_iterator;
FlagMap flags_;
FlagPtrMap flag_ptr_map_;
absl::Mutex lock_;
// Disallow
@ -169,7 +115,7 @@ class FlagRegistryLock {
} // namespace
void FlagRegistry::RegisterFlag(CommandLineFlag* flag, const void* ptr) {
void FlagRegistry::RegisterFlag(CommandLineFlag* flag) {
FlagRegistryLock registry_lock(this);
std::pair<FlagIterator, bool> ins =
flags_.insert(FlagMap::value_type(flag->Name(), flag));
@ -217,11 +163,6 @@ void FlagRegistry::RegisterFlag(CommandLineFlag* flag, const void* ptr) {
// All cases above are fatal, except for the retired flags.
std::exit(1);
}
if (ptr != nullptr) {
// This must be the first time we're seeing this flag.
flag_ptr_map_.Register(flag);
}
}
CommandLineFlag* FlagRegistry::FindFlagLocked(absl::string_view name) {
@ -247,10 +188,6 @@ CommandLineFlag* FlagRegistry::FindRetiredFlagLocked(absl::string_view name) {
return i->second;
}
CommandLineFlag* FlagRegistry::FindFlagViaPtrLocked(const void* flag_ptr) {
return flag_ptr_map_.FindByPtr(flag_ptr);
}
// --------------------------------------------------------------------
// FlagSaver
// FlagSaverImpl
@ -430,13 +367,6 @@ CommandLineFlag* FindCommandLineFlag(absl::string_view name) {
return registry->FindFlagLocked(name);
}
CommandLineFlag* FindCommandLineV1Flag(const void* flag_ptr) {
FlagRegistry* const registry = FlagRegistry::GlobalRegistry();
FlagRegistryLock frl(registry);
return registry->FindFlagViaPtrLocked(flag_ptr);
}
CommandLineFlag* FindRetiredFlag(absl::string_view name) {
FlagRegistry* const registry = FlagRegistry::GlobalRegistry();
FlagRegistryLock frl(registry);
@ -477,8 +407,8 @@ void GetAllFlags(std::vector<CommandLineFlagInfo>* OUTPUT) {
// --------------------------------------------------------------------
bool RegisterCommandLineFlag(CommandLineFlag* flag, const void* ptr) {
FlagRegistry::GlobalRegistry()->RegisterFlag(flag, ptr);
bool RegisterCommandLineFlag(CommandLineFlag* flag) {
FlagRegistry::GlobalRegistry()->RegisterFlag(flag);
return true;
}
@ -492,7 +422,7 @@ bool Retire(FlagOpFn ops, FlagMarshallingOpFn marshalling_ops,
/*filename_arg=*/"RETIRED", ops, marshalling_ops,
/*initial_value_gen=*/nullptr,
/*retired_arg=*/true, nullptr, nullptr);
FlagRegistry::GlobalRegistry()->RegisterFlag(flag, nullptr);
FlagRegistry::GlobalRegistry()->RegisterFlag(flag);
return true;
}

View file

@ -57,7 +57,6 @@ void FillCommandLineFlagInfo(CommandLineFlag* flag,
//-----------------------------------------------------------------------------
CommandLineFlag* FindCommandLineFlag(absl::string_view name);
CommandLineFlag* FindCommandLineV1Flag(const void* flag_ptr);
CommandLineFlag* FindRetiredFlag(absl::string_view name);
// Executes specified visitor for each non-retired flag in the registry.
@ -74,7 +73,7 @@ void GetAllFlags(std::vector<CommandLineFlagInfo>* OUTPUT);
//-----------------------------------------------------------------------------
bool RegisterCommandLineFlag(CommandLineFlag*, const void* ptr = nullptr);
bool RegisterCommandLineFlag(CommandLineFlag*);
//-----------------------------------------------------------------------------
// Retired registrations: