Skip to content

Commit 522606b

Browse files
ezbrcopybara-github
authored andcommitted
Fix some ClangTidy warnings in raw_hash_set code.
PiperOrigin-RevId: 493993005 Change-Id: I0705be8678022a9e08a1af9972687b7955593994
1 parent ec583f2 commit 522606b

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

absl/container/internal/raw_hash_set.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <atomic>
1818
#include <cstddef>
19+
#include <cstring>
1920

2021
#include "absl/base/config.h"
2122

@@ -182,10 +183,10 @@ void EraseMetaOnly(CommonFields& c, ctrl_t* it, size_t slot_size) {
182183
// We count how many consecutive non empties we have to the right and to the
183184
// left of `it`. If the sum is >= kWidth then there is at least one probe
184185
// window that might have seen a full group.
185-
bool was_never_full =
186-
empty_before && empty_after &&
187-
static_cast<size_t>(empty_after.TrailingZeros() +
188-
empty_before.LeadingZeros()) < Group::kWidth;
186+
bool was_never_full = empty_before && empty_after &&
187+
static_cast<size_t>(empty_after.TrailingZeros()) +
188+
empty_before.LeadingZeros() <
189+
Group::kWidth;
189190

190191
SetCtrl(c, index, was_never_full ? ctrl_t::kEmpty : ctrl_t::kDeleted,
191192
slot_size);

absl/container/internal/raw_hash_set.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,9 +1300,9 @@ class raw_hash_set {
13001300
using pointer = typename raw_hash_set::const_pointer;
13011301
using difference_type = typename raw_hash_set::difference_type;
13021302

1303-
const_iterator() {}
1303+
const_iterator() = default;
13041304
// Implicit construction from iterator.
1305-
const_iterator(iterator i) : inner_(std::move(i)) {}
1305+
const_iterator(iterator i) : inner_(std::move(i)) {} // NOLINT
13061306

13071307
reference operator*() const { return *inner_; }
13081308
pointer operator->() const { return inner_.operator->(); }
@@ -1330,6 +1330,8 @@ class raw_hash_set {
13301330
using node_type = node_handle<Policy, hash_policy_traits<Policy>, Alloc>;
13311331
using insert_return_type = InsertReturnType<iterator, node_type>;
13321332

1333+
// Note: can't use `= default` due to non-default noexcept (causes
1334+
// problems for some compilers). NOLINTNEXTLINE
13331335
raw_hash_set() noexcept(
13341336
std::is_nothrow_default_constructible<hasher>::value&&
13351337
std::is_nothrow_default_constructible<key_equal>::value&&
@@ -1494,6 +1496,7 @@ class raw_hash_set {
14941496
std::is_nothrow_move_assignable<key_equal>::value) {
14951497
// TODO(sbenza): We should only use the operations from the noexcept clause
14961498
// to make sure we actually adhere to that contract.
1499+
// NOLINTNEXTLINE: not returning *this for performance.
14971500
return move_assign(
14981501
std::move(that),
14991502
typename AllocTraits::propagate_on_container_move_assignment());

absl/container/internal/raw_hash_set_test.cc

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ struct StringEq : std::equal_to<absl::string_view> {
399399
struct StringTable
400400
: raw_hash_set<StringPolicy, StringHash, StringEq, std::allocator<int>> {
401401
using Base = typename StringTable::raw_hash_set;
402-
StringTable() {}
402+
StringTable() = default;
403403
using Base::Base;
404404
};
405405

@@ -419,7 +419,7 @@ struct Uint8Table
419419

420420
template <typename T>
421421
struct CustomAlloc : std::allocator<T> {
422-
CustomAlloc() {}
422+
CustomAlloc() = default;
423423

424424
template <typename U>
425425
explicit CustomAlloc(const CustomAlloc<U>& /*other*/) {}
@@ -446,7 +446,7 @@ struct BadFastHash {
446446
struct BadTable : raw_hash_set<IntPolicy, BadFastHash, std::equal_to<int>,
447447
std::allocator<int>> {
448448
using Base = typename BadTable::raw_hash_set;
449-
BadTable() {}
449+
BadTable() = default;
450450
using Base::Base;
451451
};
452452

@@ -1003,7 +1003,7 @@ TEST(Table, ClearBug) {
10031003
// We are checking that original and second are close enough to each other
10041004
// that they are probably still in the same group. This is not strictly
10051005
// guaranteed.
1006-
EXPECT_LT(std::abs(original - second),
1006+
EXPECT_LT(static_cast<size_t>(std::abs(original - second)),
10071007
capacity * sizeof(IntTable::value_type));
10081008
}
10091009

@@ -1080,19 +1080,6 @@ struct ProbeStats {
10801080
// Ratios total_probe_length/size for every tested table.
10811081
std::vector<double> single_table_ratios;
10821082

1083-
friend ProbeStats operator+(const ProbeStats& a, const ProbeStats& b) {
1084-
ProbeStats res = a;
1085-
res.all_probes_histogram.resize(std::max(res.all_probes_histogram.size(),
1086-
b.all_probes_histogram.size()));
1087-
std::transform(b.all_probes_histogram.begin(), b.all_probes_histogram.end(),
1088-
res.all_probes_histogram.begin(),
1089-
res.all_probes_histogram.begin(), std::plus<size_t>());
1090-
res.single_table_ratios.insert(res.single_table_ratios.end(),
1091-
b.single_table_ratios.begin(),
1092-
b.single_table_ratios.end());
1093-
return res;
1094-
}
1095-
10961083
// Average ratio total_probe_length/size over tables.
10971084
double AvgRatio() const {
10981085
return std::accumulate(single_table_ratios.begin(),
@@ -1555,7 +1542,7 @@ TEST(Table, CopyConstructWithAlloc) {
15551542
struct ExplicitAllocIntTable
15561543
: raw_hash_set<IntPolicy, container_internal::hash_default_hash<int64_t>,
15571544
std::equal_to<int64_t>, Alloc<int64_t>> {
1558-
ExplicitAllocIntTable() {}
1545+
ExplicitAllocIntTable() = default;
15591546
};
15601547

15611548
TEST(Table, AllocWithExplicitCtor) {
@@ -1943,7 +1930,7 @@ TEST(Nodes, ExtractInsert) {
19431930
EXPECT_FALSE(res.inserted);
19441931
EXPECT_THAT(*res.position, Pair(k0, ""));
19451932
EXPECT_TRUE(res.node);
1946-
EXPECT_FALSE(node);
1933+
EXPECT_FALSE(node); // NOLINT(bugprone-use-after-move)
19471934
}
19481935

19491936
TEST(Nodes, HintInsert) {
@@ -1953,7 +1940,7 @@ TEST(Nodes, HintInsert) {
19531940
auto it = t.insert(t.begin(), std::move(node));
19541941
EXPECT_THAT(t, UnorderedElementsAre(1, 2, 3));
19551942
EXPECT_EQ(*it, 1);
1956-
EXPECT_FALSE(node);
1943+
EXPECT_FALSE(node); // NOLINT(bugprone-use-after-move)
19571944

19581945
node = t.extract(2);
19591946
EXPECT_THAT(t, UnorderedElementsAre(1, 3));
@@ -1963,7 +1950,7 @@ TEST(Nodes, HintInsert) {
19631950
it = t.insert(t.begin(), std::move(node));
19641951
EXPECT_EQ(*it, 2);
19651952
// The node was not emptied by the insert call.
1966-
EXPECT_TRUE(node);
1953+
EXPECT_TRUE(node); // NOLINT(bugprone-use-after-move)
19671954
}
19681955

19691956
IntTable MakeSimpleTable(size_t size) {

0 commit comments

Comments
 (0)