summaryrefslogtreecommitdiff
path: root/absl
diff options
context:
space:
mode:
Diffstat (limited to 'absl')
-rw-r--r--absl/container/internal/btree.h16
-rw-r--r--absl/flags/internal/commandlineflag.h3
-rw-r--r--absl/flags/internal/flag.cc21
-rw-r--r--absl/flags/internal/flag.h5
-rw-r--r--absl/flags/internal/registry.cc21
-rw-r--r--absl/strings/string_view.h18
6 files changed, 26 insertions, 58 deletions
diff --git a/absl/container/internal/btree.h b/absl/container/internal/btree.h
index 8644255c..fd5c0e7a 100644
--- a/absl/container/internal/btree.h
+++ b/absl/container/internal/btree.h
@@ -1906,8 +1906,7 @@ inline auto btree<P>::insert_hint_unique(iterator position, const key_type &key,
-> std::pair<iterator, bool> {
if (!empty()) {
if (position == end() || compare_keys(key, position.key())) {
- iterator prev = position;
- if (position == begin() || compare_keys((--prev).key(), key)) {
+ if (position == begin() || compare_keys(std::prev(position).key(), key)) {
// prev.key() < key < position.key()
return {internal_emplace(position, std::forward<Args>(args)...), true};
}
@@ -1953,17 +1952,16 @@ auto btree<P>::insert_hint_multi(iterator position, ValueType &&v) -> iterator {
if (!empty()) {
const key_type &key = params_type::key(v);
if (position == end() || !compare_keys(position.key(), key)) {
- iterator prev = position;
- if (position == begin() || !compare_keys(key, (--prev).key())) {
+ if (position == begin() ||
+ !compare_keys(key, std::prev(position).key())) {
// prev.key() <= key <= position.key()
return internal_emplace(position, std::forward<ValueType>(v));
}
} else {
- iterator next = position;
- ++next;
- if (next == end() || !compare_keys(next.key(), key)) {
- // position.key() < key <= next.key()
- return internal_emplace(next, std::forward<ValueType>(v));
+ ++position;
+ if (position == end() || !compare_keys(position.key(), key)) {
+ // {original `position`}.key() < key < {current `position`}.key()
+ return internal_emplace(position, std::forward<ValueType>(v));
}
}
}
diff --git a/absl/flags/internal/commandlineflag.h b/absl/flags/internal/commandlineflag.h
index 6a0b5fad..4ac50190 100644
--- a/absl/flags/internal/commandlineflag.h
+++ b/absl/flags/internal/commandlineflag.h
@@ -178,9 +178,6 @@ class CommandLineFlag {
public:
constexpr CommandLineFlag() = default;
- // Virtual destructor
- virtual void Destroy() = 0;
-
// Not copyable/assignable.
CommandLineFlag(const CommandLineFlag&) = delete;
CommandLineFlag& operator=(const CommandLineFlag&) = delete;
diff --git a/absl/flags/internal/flag.cc b/absl/flags/internal/flag.cc
index cfc0cf4d..ba70da91 100644
--- a/absl/flags/internal/flag.cc
+++ b/absl/flags/internal/flag.cc
@@ -120,27 +120,6 @@ absl::Mutex* FlagImpl::DataGuard() const {
return reinterpret_cast<absl::Mutex*>(&data_guard_);
}
-void FlagImpl::Destroy() {
- {
- absl::MutexLock l(DataGuard());
-
- // Values are heap allocated for Abseil Flags.
- if (value_.dynamic) Delete(op_, value_.dynamic);
-
- // Release the dynamically allocated default value if any.
- if (DefaultKind() == FlagDefaultKind::kDynamicValue) {
- Delete(op_, default_src_.dynamic_value);
- }
-
- // If this flag has an assigned callback, release callback data.
- if (callback_) delete callback_;
- }
-
- absl::MutexLock l(&flag_mutex_lifetime_guard);
- DataGuard()->~Mutex();
- is_data_guard_inited_ = false;
-}
-
void FlagImpl::AssertValidType(const flags_internal::FlagOpFn op) const {
// `op` is the unmarshaling operation corresponding to the declaration
// visibile at the call site. `op_` is the Flag's defined unmarshalling
diff --git a/absl/flags/internal/flag.h b/absl/flags/internal/flag.h
index c6c4a2f7..ef30a22f 100644
--- a/absl/flags/internal/flag.h
+++ b/absl/flags/internal/flag.h
@@ -290,9 +290,6 @@ class FlagImpl {
default_src_(default_value_gen),
data_guard_{} {}
- // Forces destruction of the Flag's data.
- void Destroy();
-
// Constant access methods
absl::string_view Name() const;
std::string Filename() const;
@@ -515,8 +512,6 @@ class Flag final : public flags_internal::CommandLineFlag {
private:
friend class FlagState<T>;
- void Destroy() override { impl_.Destroy(); }
-
void Read(void* dst) const override { impl_.Read(dst); }
FlagOpFn TypeId() const override { return &FlagOps<T>; }
diff --git a/absl/flags/internal/registry.cc b/absl/flags/internal/registry.cc
index 7889b1f3..2ef16e84 100644
--- a/absl/flags/internal/registry.cc
+++ b/absl/flags/internal/registry.cc
@@ -57,11 +57,7 @@ namespace flags_internal {
class FlagRegistry {
public:
FlagRegistry() = default;
- ~FlagRegistry() {
- for (auto& p : flags_) {
- p.second->Destroy();
- }
- }
+ ~FlagRegistry() = default;
// Store a flag in this registry. Takes ownership of *flag.
void RegisterFlag(CommandLineFlag* flag);
@@ -113,6 +109,7 @@ class FlagRegistryLock {
FlagRegistry* const fr_;
};
+void DestroyRetiredFlag(CommandLineFlag* flag);
} // namespace
void FlagRegistry::RegisterFlag(CommandLineFlag* flag) {
@@ -140,8 +137,8 @@ void FlagRegistry::RegisterFlag(CommandLineFlag* flag) {
flag->Typename(), "', respectively."),
true);
} else if (old_flag->IsRetired()) {
- // Retired definitions are idempotent. Just keep the old one.
- flag->Destroy();
+ // Retired flag can just be deleted.
+ DestroyRetiredFlag(flag);
return;
} else if (old_flag->Filename() != flag->Filename()) {
flags_internal::ReportUsageError(
@@ -291,11 +288,6 @@ class RetiredFlagObj final : public flags_internal::CommandLineFlag {
: name_(name), op_(ops) {}
private:
- void Destroy() override {
- // Values are heap allocated for Retired Flags.
- delete this;
- }
-
absl::string_view Name() const override { return name_; }
std::string Filename() const override { return "RETIRED"; }
absl::string_view Typename() const override { return ""; }
@@ -328,6 +320,11 @@ class RetiredFlagObj final : public flags_internal::CommandLineFlag {
const FlagOpFn op_;
};
+void DestroyRetiredFlag(flags_internal::CommandLineFlag* flag) {
+ assert(flag->IsRetired());
+ delete static_cast<RetiredFlagObj*>(flag);
+}
+
} // namespace
bool Retire(const char* name, FlagOpFn ops) {
diff --git a/absl/strings/string_view.h b/absl/strings/string_view.h
index 418dbc80..1861ea62 100644
--- a/absl/strings/string_view.h
+++ b/absl/strings/string_view.h
@@ -398,12 +398,11 @@ class string_view {
// on the respective sizes of the two `string_view`s to determine which is
// smaller, equal, or greater.
constexpr int compare(string_view x) const noexcept {
- return CompareImpl(
- length_, x.length_,
- length_ == 0 || x.length_ == 0
- ? 0
- : ABSL_INTERNAL_STRING_VIEW_MEMCMP(
- ptr_, x.ptr_, length_ < x.length_ ? length_ : x.length_));
+ return CompareImpl(length_, x.length_,
+ Min(length_, x.length_) == 0
+ ? 0
+ : ABSL_INTERNAL_STRING_VIEW_MEMCMP(
+ ptr_, x.ptr_, Min(length_, x.length_)));
}
// Overload of `string_view::compare()` for comparing a substring of the
@@ -541,12 +540,15 @@ class string_view {
#endif
}
+ static constexpr size_t Min(size_type length_a, size_type length_b) {
+ return length_a < length_b ? length_a : length_b;
+ }
+
static constexpr int CompareImpl(size_type length_a, size_type length_b,
int compare_result) {
return compare_result == 0 ? static_cast<int>(length_a > length_b) -
static_cast<int>(length_a < length_b)
- : static_cast<int>(compare_result > 0) -
- static_cast<int>(compare_result < 0);
+ : (compare_result < 0 ? -1 : 1);
}
const char* ptr_;