Skip to content

Commit 63b2338

Browse files
code style fix
1 parent 98543fc commit 63b2338

File tree

1 file changed

+29
-36
lines changed

1 file changed

+29
-36
lines changed

sdk/include/opentelemetry/sdk/metrics/view/attributes_processor.h

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,64 +26,55 @@ using MetricAttributes = opentelemetry::sdk::metrics::FilteredOrderedAttributeMa
2626
* Generic FNV hash implementation
2727
*/
2828

29-
template <typename Ty, size_t s>
30-
struct fnv_magic_prime_number
31-
{
32-
static constexpr const Ty value = 0x01000193U;
33-
};
29+
template <typename Ty, size_t Size>
30+
struct FnvPrime;
3431

3532
template <typename Ty>
36-
struct fnv_magic_prime_number<Ty, 8>
33+
struct FnvPrime<Ty, 4>
3734
{
38-
static constexpr const Ty value = 0x100000001b3ULL;
35+
static constexpr Ty value = static_cast<Ty>(0x01000193U);
3936
};
4037

41-
template <typename Ty, size_t s>
42-
struct fnv_magic_offset_basis
38+
template <typename Ty>
39+
struct FnvPrime<Ty, 8>
4340
{
44-
static constexpr const Ty value = 0x811C9DC5U;
45-
46-
static constexpr Ty fix(Ty hval) { return hval; }
41+
static constexpr Ty value = static_cast<Ty>(0x100000001b3ULL);
4742
};
4843

44+
// FNV offset basis values
45+
template <typename Ty, size_t Size>
46+
struct FnvOffset;
47+
4948
template <typename Ty>
50-
struct fnv_magic_offset_basis<Ty, 8>
49+
struct FnvOffset<Ty, 4>
5150
{
52-
static constexpr const Ty value = 0xCBF29CE484222325ULL;
51+
static constexpr Ty value = static_cast<Ty>(0x811C9DC5U);
5352

54-
static constexpr Ty fix(Ty hval) { return hval ^ (hval >> 32); }
53+
static constexpr Ty Fix(Ty hval) noexcept { return hval; }
5554
};
5655

5756
template <typename Ty>
58-
Ty fnv_n_buf(const void *buf, size_t len, Ty hval = fnv_magic_offset_basis<Ty, sizeof(Ty)>::value)
57+
struct FnvOffset<Ty, 8>
5958
{
60-
const unsigned char *bp = reinterpret_cast<const unsigned char *>(buf);
61-
const unsigned char *be = bp + len;
62-
Ty mn = fnv_magic_prime_number<Ty, sizeof(Ty)>::value;
59+
static constexpr Ty value = static_cast<Ty>(0xCBF29CE484222325ULL);
6360

64-
while (bp < be)
65-
{
66-
hval *= mn;
67-
hval ^= static_cast<Ty>(*bp++);
68-
}
69-
70-
return fnv_magic_offset_basis<Ty, sizeof(Ty)>::fix(hval);
71-
}
61+
static constexpr Ty Fix(Ty hval) noexcept { return hval ^ (hval >> 32); }
62+
};
7263

64+
// FNV-1a
7365
template <typename Ty>
74-
Ty fnv_n_buf_a(const void *buf, size_t len, Ty hval = fnv_magic_offset_basis<Ty, sizeof(Ty)>::value)
66+
inline Ty Fnv1a(const void *buf, size_t len, Ty hval = FnvOffset<Ty, sizeof(Ty)>::value) noexcept
7567
{
7668
const unsigned char *bp = reinterpret_cast<const unsigned char *>(buf);
7769
const unsigned char *be = bp + len;
78-
Ty mn = fnv_magic_prime_number<Ty, sizeof(Ty)>::value;
70+
Ty prime = FnvPrime<Ty, sizeof(Ty)>::value;
7971

8072
while (bp < be)
8173
{
8274
hval ^= static_cast<Ty>(*bp++);
83-
hval *= mn;
75+
hval *= prime;
8476
}
85-
86-
return fnv_magic_offset_basis<Ty, sizeof(Ty)>::fix(hval);
77+
return FnvOffset<Ty, sizeof(Ty)>::Fix(hval);
8778
}
8879

8980
/**
@@ -101,12 +92,12 @@ struct StringViewHash
10192

10293
std::size_t operator()(const std::string &s) const noexcept
10394
{
104-
return fnv_n_buf_a<std::size_t>(s.data(), s.size());
95+
return Fnv1a<std::size_t>(s.data(), s.size());
10596
}
10697

10798
std::size_t operator()(opentelemetry::nostd::string_view sv) const noexcept
10899
{
109-
return fnv_n_buf_a<std::size_t>(sv.data(), sv.size());
100+
return Fnv1a<std::size_t>(sv.data(), sv.size());
110101
}
111102
};
112103

@@ -121,8 +112,10 @@ struct StringViewEqual
121112
template <typename Lhs, typename Rhs>
122113
bool operator()(const Lhs &lhs, const Rhs &rhs) const noexcept
123114
{
124-
opentelemetry::nostd::string_view lsv(lhs.data(), lhs.size());
125-
opentelemetry::nostd::string_view rsv(rhs.data(), rhs.size());
115+
opentelemetry::nostd::string_view lsv(opentelemetry::nostd::data(lhs),
116+
opentelemetry::nostd::size(lhs));
117+
opentelemetry::nostd::string_view rsv(opentelemetry::nostd::data(rhs),
118+
opentelemetry::nostd::size(rhs));
126119

127120
return lsv.size() == rsv.size() && std::memcmp(lsv.data(), rsv.data(), lsv.size()) == 0;
128121
}

0 commit comments

Comments
 (0)