summaryrefslogtreecommitdiff
path: root/absl/flags/internal/flag.h
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2020-02-07 13:06:07 -0800
committerGravatar Andy Getz <durandal@google.com>2020-02-07 16:58:49 -0500
commitd95d1567165d449e4c213ea31a15cbb112a9865f (patch)
treefee6dca04f49a417f87c4c96551f366279cf9b61 /absl/flags/internal/flag.h
parent24713a7036a81498334807fa5c7ad3cb7c643711 (diff)
Export of internal Abseil changes
-- 832be2d52d7695cf72fd70248909791fb8ad1003 by Gennadiy Rozental <rogeeff@google.com>: Migrate some FlagImpl fields to bit fields. To save padding space we are migrating some fields representing bool and enums into bit fields. Eventually we'll use remaining padding space for call_once control flag. No other semantic changes made in this CL. PiperOrigin-RevId: 293878165 -- 09162bba5fd8eddacfd732d46fcfeb33074a259f by Samuel Benzaquen <sbenza@google.com>: Correctly initialize the `length_mod` member. Now that it is a raw enum, the default initialization is not enough. PiperOrigin-RevId: 293827817 -- 842b7b805d75c5ab670c52ccd7368cdeba11853d by Matthew Brown <matthewbr@google.com>: Move str_format_internal::LengthMod from extension.h to parser.h; change to enum PiperOrigin-RevId: 293697274 GitOrigin-RevId: 832be2d52d7695cf72fd70248909791fb8ad1003 Change-Id: I90899519e9480543e22638616fdf31a41e7f75c0
Diffstat (limited to 'absl/flags/internal/flag.h')
-rw-r--r--absl/flags/internal/flag.h48
1 files changed, 29 insertions, 19 deletions
diff --git a/absl/flags/internal/flag.h b/absl/flags/internal/flag.h
index cc07dce1..b5471fa8 100644
--- a/absl/flags/internal/flag.h
+++ b/absl/flags/internal/flag.h
@@ -87,7 +87,7 @@ union FlagHelpMsg {
HelpGenFunc gen_func;
};
-enum class FlagHelpKind : int8_t { kLiteral, kGenFunc };
+enum class FlagHelpKind : uint8_t { kLiteral = 0, kGenFunc = 1 };
struct FlagHelpArg {
FlagHelpMsg source;
@@ -147,7 +147,7 @@ union FlagDefaultSrc {
FlagDfltGenFunc gen_func;
};
-enum class FlagDefaultSrcKind : int8_t { kDynamicValue, kGenFunc };
+enum class FlagDefaultKind : uint8_t { kDynamicValue = 0, kGenFunc = 1 };
///////////////////////////////////////////////////////////////////////////////
// Flag current value auxiliary structs.
@@ -279,8 +279,14 @@ class FlagImpl {
op_(op),
marshalling_op_(marshalling_op),
help_(help.source),
- help_source_kind_(help.kind),
- def_kind_(FlagDefaultSrcKind::kGenFunc),
+ help_source_kind_(static_cast<uint8_t>(help.kind)),
+ def_kind_(static_cast<uint8_t>(FlagDefaultKind::kGenFunc)),
+ is_data_guard_inited_(false),
+ modified_(false),
+ on_command_line_(false),
+ inited_(false),
+ counter_(0),
+ callback_(nullptr),
default_src_(default_value_gen),
data_guard_{} {}
@@ -370,6 +376,14 @@ class FlagImpl {
// Lazy initialization of the Flag's data.
void Init();
+ FlagHelpKind HelpSourceKind() const {
+ return static_cast<FlagHelpKind>(help_source_kind_);
+ }
+ FlagDefaultKind DefaultKind() const
+ ABSL_EXCLUSIVE_LOCKS_REQUIRED(*DataGuard()) {
+ return static_cast<FlagDefaultKind>(def_kind_);
+ }
+
// Immutable flag's state.
// Flags name passed to ABSL_FLAG as second arg.
@@ -383,35 +397,31 @@ class FlagImpl {
// Help message literal or function to generate it.
const FlagHelpMsg help_;
// Indicates if help message was supplied as literal or generator func.
- const FlagHelpKind help_source_kind_;
-
- // Indicates that the Flag state is initialized.
- std::atomic<bool> inited_{false};
+ const uint8_t help_source_kind_ : 1;
// Mutable flag's state (guarded by `data_guard_`).
+ // If def_kind_ == kDynamicValue, default_src_ holds a dynamically allocated
+ // value.
+ uint8_t def_kind_ : 1 ABSL_GUARDED_BY(*DataGuard());
// Protects against multiple concurrent constructions of `data_guard_`.
- bool is_data_guard_inited_ = false;
+ bool is_data_guard_inited_ : 1;
// Has this flag's value been modified?
- bool modified_ ABSL_GUARDED_BY(*DataGuard()) = false;
+ bool modified_ : 1 ABSL_GUARDED_BY(*DataGuard());
// Has this flag been specified on command line.
- bool on_command_line_ ABSL_GUARDED_BY(*DataGuard()) = false;
+ bool on_command_line_ : 1 ABSL_GUARDED_BY(*DataGuard());
+ // Indicates that the flag state is initialized.
+ std::atomic<bool> inited_;
// Mutation counter
- int64_t counter_ ABSL_GUARDED_BY(*DataGuard()) = 0;
-
+ int64_t counter_ ABSL_GUARDED_BY(*DataGuard());
// Optional flag's callback and absl::Mutex to guard the invocations.
- FlagCallback* callback_ ABSL_GUARDED_BY(*DataGuard()) = nullptr;
-
- // If def_kind_ == kDynamicValue, default_src_ holds a dynamically allocated
- // value.
- FlagDefaultSrcKind def_kind_ ABSL_GUARDED_BY(*DataGuard());
+ FlagCallback* callback_ ABSL_GUARDED_BY(*DataGuard());
// Either a pointer to the function generating the default value based on the
// value specified in ABSL_FLAG or pointer to the dynamically set default
// value via SetCommandLineOptionWithMode. def_kind_ is used to distinguish
// these two cases.
FlagDefaultSrc default_src_ ABSL_GUARDED_BY(*DataGuard());
-
// Current Flag Value
FlagValue value_;