summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--absl/base/optimization.h2
-rw-r--r--absl/base/optimization_test.cc15
-rw-r--r--absl/flags/flag.h11
-rw-r--r--absl/flags/flag_test_defs.cc2
-rw-r--r--absl/flags/internal/registry.h17
-rw-r--r--absl/flags/reflection.cc17
-rw-r--r--absl/strings/cord.cc2
-rw-r--r--absl/time/internal/cctz/src/time_zone_info.cc12
-rw-r--r--absl/time/internal/cctz/src/time_zone_info.h2
9 files changed, 37 insertions, 43 deletions
diff --git a/absl/base/optimization.h b/absl/base/optimization.h
index 92bf9cd3..2e31376c 100644
--- a/absl/base/optimization.h
+++ b/absl/base/optimization.h
@@ -171,7 +171,7 @@
// to yield performance improvements.
#if ABSL_HAVE_BUILTIN(__builtin_expect) || \
(defined(__GNUC__) && !defined(__clang__))
-#define ABSL_PREDICT_FALSE(x) (__builtin_expect(x, 0))
+#define ABSL_PREDICT_FALSE(x) (__builtin_expect(false || (x), false))
#define ABSL_PREDICT_TRUE(x) (__builtin_expect(false || (x), true))
#else
#define ABSL_PREDICT_FALSE(x) (x)
diff --git a/absl/base/optimization_test.cc b/absl/base/optimization_test.cc
index 894b68f8..e83369f3 100644
--- a/absl/base/optimization_test.cc
+++ b/absl/base/optimization_test.cc
@@ -74,9 +74,8 @@ TEST(PredictTest, Pointer) {
const int *null_intptr = nullptr;
EXPECT_TRUE(ABSL_PREDICT_TRUE(good_intptr));
EXPECT_FALSE(ABSL_PREDICT_TRUE(null_intptr));
- // The following doesn't compile:
- // EXPECT_TRUE(ABSL_PREDICT_FALSE(good_intptr));
- // EXPECT_FALSE(ABSL_PREDICT_FALSE(null_intptr));
+ EXPECT_TRUE(ABSL_PREDICT_FALSE(good_intptr));
+ EXPECT_FALSE(ABSL_PREDICT_FALSE(null_intptr));
}
TEST(PredictTest, Optional) {
@@ -85,9 +84,8 @@ TEST(PredictTest, Optional) {
absl::optional<bool> no_value;
EXPECT_TRUE(ABSL_PREDICT_TRUE(has_value));
EXPECT_FALSE(ABSL_PREDICT_TRUE(no_value));
- // The following doesn't compile:
- // EXPECT_TRUE(ABSL_PREDICT_FALSE(has_value));
- // EXPECT_FALSE(ABSL_PREDICT_FALSE(no_value));
+ EXPECT_TRUE(ABSL_PREDICT_FALSE(has_value));
+ EXPECT_FALSE(ABSL_PREDICT_FALSE(no_value));
}
class ImplictlyConvertibleToBool {
@@ -124,9 +122,8 @@ TEST(PredictTest, ExplicitBoolConversion) {
const ExplictlyConvertibleToBool is_false(false);
if (!ABSL_PREDICT_TRUE(is_true)) ADD_FAILURE();
if (ABSL_PREDICT_TRUE(is_false)) ADD_FAILURE();
- // The following doesn't compile:
- // if (!ABSL_PREDICT_FALSE(is_true)) ADD_FAILURE();
- // if (ABSL_PREDICT_FALSE(is_false)) ADD_FAILURE();
+ if (!ABSL_PREDICT_FALSE(is_true)) ADD_FAILURE();
+ if (ABSL_PREDICT_FALSE(is_false)) ADD_FAILURE();
}
} // namespace
diff --git a/absl/flags/flag.h b/absl/flags/flag.h
index 90dc2894..e1707252 100644
--- a/absl/flags/flag.h
+++ b/absl/flags/flag.h
@@ -379,11 +379,10 @@ ABSL_NAMESPACE_END
//
// `default_value` is only used as a double check on the type. `explanation` is
// unused.
-// TODO(rogeeff): Return an anonymous struct instead of bool, and place it into
-// the unnamed namespace.
-#define ABSL_RETIRED_FLAG(type, flagname, default_value, explanation) \
- ABSL_ATTRIBUTE_UNUSED static const bool ignored_##flagname = \
- ([] { return type(default_value); }, \
- absl::flags_internal::RetiredFlag<type>(#flagname))
+// TODO(rogeeff): replace RETIRED_FLAGS with FLAGS once forward declarations of
+// retired flags are cleaned up.
+#define ABSL_RETIRED_FLAG(type, name, default_value, explanation) \
+ ABSL_ATTRIBUTE_UNUSED static const absl::flags_internal::RetiredFlag<type> \
+ RETIRED_FLAGS_##name(#name)
#endif // ABSL_FLAGS_FLAG_H_
diff --git a/absl/flags/flag_test_defs.cc b/absl/flags/flag_test_defs.cc
index 49f91dee..3366c580 100644
--- a/absl/flags/flag_test_defs.cc
+++ b/absl/flags/flag_test_defs.cc
@@ -20,5 +20,3 @@
ABSL_FLAG(int, mistyped_int_flag, 0, "");
ABSL_FLAG(std::string, mistyped_string_flag, "", "");
-ABSL_RETIRED_FLAG(bool, old_bool_flag, true,
- "repetition of retired flag definition");
diff --git a/absl/flags/internal/registry.h b/absl/flags/internal/registry.h
index 6f5006a0..5f85ded5 100644
--- a/absl/flags/internal/registry.h
+++ b/absl/flags/internal/registry.h
@@ -74,13 +74,22 @@ bool RegisterCommandLineFlag(CommandLineFlag&);
//
// Retire flag with name "name" and type indicated by ops.
-bool Retire(const char* name, FlagFastTypeId type_id);
+void Retire(const char* name, FlagFastTypeId type_id, char* buf);
+
+constexpr size_t kRetiredFlagObjSize = 3 * sizeof(void*);
+constexpr size_t kRetiredFlagObjAlignment = alignof(void*);
// Registered a retired flag with name 'flag_name' and type 'T'.
template <typename T>
-inline bool RetiredFlag(const char* flag_name) {
- return flags_internal::Retire(flag_name, base_internal::FastTypeId<T>());
-}
+class RetiredFlag {
+ public:
+ explicit RetiredFlag(const char* flag_name) {
+ flags_internal::Retire(flag_name, base_internal::FastTypeId<T>(), buf_);
+ }
+
+ private:
+ alignas(kRetiredFlagObjAlignment) char buf_[kRetiredFlagObjSize];
+};
} // namespace flags_internal
ABSL_NAMESPACE_END
diff --git a/absl/flags/reflection.cc b/absl/flags/reflection.cc
index 1b025835..e4145b34 100644
--- a/absl/flags/reflection.cc
+++ b/absl/flags/reflection.cc
@@ -99,8 +99,6 @@ class FlagRegistryLock {
FlagRegistry& fr_;
};
-void DestroyRetiredFlag(CommandLineFlag& flag);
-
} // namespace
void FlagRegistry::RegisterFlag(CommandLineFlag& flag) {
@@ -125,8 +123,6 @@ void FlagRegistry::RegisterFlag(CommandLineFlag& flag) {
old_flag.Filename(), "' and '", flag.Filename(), "'."),
true);
} else if (old_flag.IsRetired()) {
- // Retired flag can just be deleted.
- DestroyRetiredFlag(flag);
return;
} else if (old_flag.Filename() != flag.Filename()) {
flags_internal::ReportUsageError(
@@ -241,17 +237,14 @@ class RetiredFlagObj final : public CommandLineFlag {
const FlagFastTypeId type_id_;
};
-void DestroyRetiredFlag(CommandLineFlag& flag) {
- assert(flag.IsRetired());
- delete static_cast<RetiredFlagObj*>(&flag);
-}
-
} // namespace
-bool Retire(const char* name, FlagFastTypeId type_id) {
- auto* flag = new flags_internal::RetiredFlagObj(name, type_id);
+void Retire(const char* name, FlagFastTypeId type_id, char* buf) {
+ static_assert(sizeof(RetiredFlagObj) == kRetiredFlagObjSize, "");
+ static_assert(alignof(RetiredFlagObj) == kRetiredFlagObjAlignment, "");
+ auto* flag = ::new (static_cast<void*>(buf))
+ flags_internal::RetiredFlagObj(name, type_id);
FlagRegistry::GlobalRegistry().RegisterFlag(*flag);
- return true;
}
// --------------------------------------------------------------------
diff --git a/absl/strings/cord.cc b/absl/strings/cord.cc
index 70c399c1..920dcc67 100644
--- a/absl/strings/cord.cc
+++ b/absl/strings/cord.cc
@@ -549,7 +549,7 @@ void Cord::InlineRep::AppendTree(CordRep* tree) {
}
void Cord::InlineRep::PrependTree(CordRep* tree) {
- if (tree == nullptr) return;
+ assert(tree != nullptr);
size_t len = data_[kMaxInline];
if (len == 0) {
set_tree(tree);
diff --git a/absl/time/internal/cctz/src/time_zone_info.cc b/absl/time/internal/cctz/src/time_zone_info.cc
index c7bf0447..8039353e 100644
--- a/absl/time/internal/cctz/src/time_zone_info.cc
+++ b/absl/time/internal/cctz/src/time_zone_info.cc
@@ -295,7 +295,7 @@ bool TimeZoneInfo::EquivTransitions(std::uint_fast8_t tt1_index,
// Find/make a transition type with these attributes.
bool TimeZoneInfo::GetTransitionType(std::int_fast32_t utc_offset, bool is_dst,
const std::string& abbr,
- std::uint_fast8_t* index) {
+ std::uint_least8_t* index) {
std::size_t type_index = 0;
std::size_t abbr_index = abbreviations_.size();
for (; type_index != transition_types_.size(); ++type_index) {
@@ -334,7 +334,7 @@ bool TimeZoneInfo::ExtendTransitions() {
if (!ParsePosixSpec(future_spec_, &posix)) return false;
// Find transition type for the future std specification.
- std::uint_fast8_t std_ti;
+ std::uint_least8_t std_ti;
if (!GetTransitionType(posix.std_offset, false, posix.std_abbr, &std_ti))
return false;
@@ -345,7 +345,7 @@ bool TimeZoneInfo::ExtendTransitions() {
}
// Find transition type for the future dst specification.
- std::uint_fast8_t dst_ti;
+ std::uint_least8_t dst_ti;
if (!GetTransitionType(posix.dst_offset, true, posix.dst_abbr, &dst_ti))
return false;
@@ -365,10 +365,8 @@ bool TimeZoneInfo::ExtendTransitions() {
std::int_fast64_t jan1_time = jan1 - civil_second();
int jan1_weekday = ToPosixWeekday(get_weekday(jan1));
- Transition dst = {0, static_cast<uint_least8_t>(dst_ti), civil_second(),
- civil_second()};
- Transition std = {0, static_cast<uint_least8_t>(std_ti), civil_second(),
- civil_second()};
+ Transition dst = {0, dst_ti, civil_second(), civil_second()};
+ Transition std = {0, std_ti, civil_second(), civil_second()};
for (const year_t limit = last_year_ + 400;; ++last_year_) {
auto dst_trans_off = TransOffset(leap_year, jan1_weekday, posix.dst_start);
auto std_trans_off = TransOffset(leap_year, jan1_weekday, posix.dst_end);
diff --git a/absl/time/internal/cctz/src/time_zone_info.h b/absl/time/internal/cctz/src/time_zone_info.h
index 068e34be..2467ff55 100644
--- a/absl/time/internal/cctz/src/time_zone_info.h
+++ b/absl/time/internal/cctz/src/time_zone_info.h
@@ -96,7 +96,7 @@ class TimeZoneInfo : public TimeZoneIf {
};
bool GetTransitionType(std::int_fast32_t utc_offset, bool is_dst,
- const std::string& abbr, std::uint_fast8_t* index);
+ const std::string& abbr, std::uint_least8_t* index);
bool EquivTransitions(std::uint_fast8_t tt1_index,
std::uint_fast8_t tt2_index) const;
bool ExtendTransitions();