Skip to content

Commit c9efadb

Browse files
jckingcopybara-github
authored andcommitted
Inline Value::GetBool and Value::AsBool
PiperOrigin-RevId: 743211296
1 parent 1c391a5 commit c9efadb

2 files changed

Lines changed: 11 additions & 15 deletions

File tree

common/value.cc

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,14 +1758,6 @@ Value Value::WrapMapFieldValue(
17581758
}
17591759
}
17601760

1761-
absl::optional<BoolValue> Value::AsBool() const {
1762-
if (const auto* alternative = variant_.As<BoolValue>();
1763-
alternative != nullptr) {
1764-
return *alternative;
1765-
}
1766-
return absl::nullopt;
1767-
}
1768-
17691761
optional_ref<const BytesValue> Value::AsBytes() const& {
17701762
if (const auto* alternative = variant_.As<BytesValue>();
17711763
alternative != nullptr) {
@@ -2178,11 +2170,6 @@ absl::optional<UnknownValue> Value::AsUnknown() && {
21782170
return absl::nullopt;
21792171
}
21802172

2181-
BoolValue Value::GetBool() const {
2182-
ABSL_DCHECK(IsBool()) << *this;
2183-
return variant_.Get<BoolValue>();
2184-
}
2185-
21862173
const BytesValue& Value::GetBytes() const& {
21872174
ABSL_DCHECK(IsBytes()) << *this;
21882175
return variant_.Get<BytesValue>();

common/value.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,13 @@ class Value final : private common_internal::ValueMixin<Value> {
722722
// Performs a checked cast from a value to a bool value,
723723
// returning a non-empty optional with either a value or reference to the
724724
// bool value. Otherwise an empty optional is returned.
725-
absl::optional<BoolValue> AsBool() const;
725+
absl::optional<BoolValue> AsBool() const {
726+
if (const auto* alternative = variant_.As<BoolValue>();
727+
alternative != nullptr) {
728+
return *alternative;
729+
}
730+
return absl::nullopt;
731+
}
726732

727733
// Performs a checked cast from a value to a bytes value,
728734
// returning a non-empty optional with either a value or reference to the
@@ -1661,7 +1667,10 @@ class Value final : private common_internal::ValueMixin<Value> {
16611667
// Performs an unchecked cast from a value to a bool value. In
16621668
// debug builds a best effort is made to crash. If `IsBool()` would return
16631669
// false, calling this method is undefined behavior.
1664-
BoolValue GetBool() const;
1670+
BoolValue GetBool() const {
1671+
ABSL_DCHECK(IsBool()) << *this;
1672+
return variant_.Get<BoolValue>();
1673+
}
16651674

16661675
// Performs an unchecked cast from a value to a bytes value. In
16671676
// debug builds a best effort is made to crash. If `IsBytes()` would return

0 commit comments

Comments
 (0)