Skip to content

Commit 6d42338

Browse files
generatedunixname537391475639613meta-codesync[bot]
authored andcommitted
{Cosmetic} modernize-avoid-c-arrays
Reviewed By: SeaOtocinclus Differential Revision: D84804548 fbshipit-source-id: 0ab7bb5f0cfacf095d9517bd57b5ed83925e4ff9
1 parent 4ff9758 commit 6d42338

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

core/data_provider/data_types/Uuid.h

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

1717
#pragma once
1818

19+
#include <array>
1920
#include <cstdint>
2021
#include <cstring>
2122

@@ -39,7 +40,7 @@ struct alignas(8) Uuid {
3940
static Uuid createFromIds(std::uint64_t id1, std::uint64_t id2);
4041

4142
/// This function is added to easy conversion between vision uuid and a lot uuid
42-
static Uuid createFromBytes(const std::uint8_t bytes[kStaticSize]);
43+
static Uuid createFromBytes(const std::array<std::uint8_t, kStaticSize>& bytes);
4344

4445
/// Returns an invalid UUID (all zeros).
4546
// Note: Consider making default constructor private once we move away from cereal.
@@ -58,7 +59,7 @@ struct alignas(8) Uuid {
5859
return !isValid();
5960
}
6061

61-
std::uint8_t value[kStaticSize] = {0};
62+
std::array<std::uint8_t, kStaticSize> value = {};
6263

6364
}; // struct Uuid
6465

@@ -171,17 +172,17 @@ std::pair<Uuid<Purpose>, bool> Uuid<Purpose>::createFromString(const std::string
171172
template <typename Purpose>
172173
Uuid<Purpose> Uuid<Purpose>::createFromIds(std::uint64_t id1, std::uint64_t id2) {
173174
Uuid<Purpose> output;
174-
auto* val64Ptr = reinterpret_cast<std::uint64_t*>(output.value);
175+
auto* val64Ptr = reinterpret_cast<std::uint64_t*>(output.value.data());
175176
val64Ptr[0] = id1;
176177
val64Ptr[1] = id2;
177178
return output;
178179
}
179180

180181
template <typename Purpose>
181-
Uuid<Purpose> Uuid<Purpose>::createFromBytes(const std::uint8_t bytes[kStaticSize]) {
182+
Uuid<Purpose> Uuid<Purpose>::createFromBytes(const std::array<std::uint8_t, kStaticSize>& bytes) {
182183
Uuid<Purpose> output;
183-
auto* val64Ptr = reinterpret_cast<std::uint64_t*>(output.value);
184-
const auto* inPtr = (const uint64_t*)(bytes);
184+
auto* val64Ptr = reinterpret_cast<std::uint64_t*>(output.value.data());
185+
const auto* inPtr = (const uint64_t*)(bytes.data());
185186
val64Ptr[0] = inPtr[0];
186187
val64Ptr[1] = inPtr[1];
187188
return output;
@@ -226,16 +227,16 @@ Uuid<NewPurpose> Uuid<Purpose>::repurposedClone() const {
226227

227228
template <typename Purpose>
228229
inline bool Uuid<Purpose>::isValid() const {
229-
const auto* ptr = reinterpret_cast<const std::uint64_t*>(this->value);
230+
const auto* ptr = reinterpret_cast<const std::uint64_t*>(this->value.data());
230231
return ptr[0] != 0 || ptr[1] != 0;
231232
}
232233

233234
template <typename Purpose>
234235
inline bool operator==(Uuid<Purpose> a, Uuid<Purpose> b) {
235236
// Using explicit cast to 64-bit numbers yields slightly better assembly code than relying on the
236237
// compiler to optimize std::memcmp (tested with godbolt.org for both x86_64 and arm64).
237-
const auto* aPtr = reinterpret_cast<const std::uint64_t*>(a.value);
238-
const auto* bPtr = reinterpret_cast<const std::uint64_t*>(b.value);
238+
const auto* aPtr = reinterpret_cast<const std::uint64_t*>(a.value.data());
239+
const auto* bPtr = reinterpret_cast<const std::uint64_t*>(b.value.data());
239240
return (aPtr[0] == bPtr[0] && aPtr[1] == bPtr[1]);
240241
}
241242

@@ -250,8 +251,8 @@ inline bool operator<(Uuid<Purpose> a, Uuid<Purpose> b) {
250251
// not big endian. The actual order doesn't matter as long as it's consistent, hence we simply
251252
// cast to 64-bit numbers.
252253
// godbolt.org shows that this results in quite few instructions on both x86_64 and arm64.
253-
const auto* aPtr = reinterpret_cast<const std::uint64_t*>(a.value);
254-
const auto* bPtr = reinterpret_cast<const std::uint64_t*>(b.value);
254+
const auto* aPtr = reinterpret_cast<const std::uint64_t*>(a.value.data());
255+
const auto* bPtr = reinterpret_cast<const std::uint64_t*>(b.value.data());
255256
if (aPtr[0] == bPtr[0]) {
256257
return aPtr[1] < bPtr[1];
257258
}
@@ -279,10 +280,10 @@ struct hash<projectaria::tools::data_provider::Uuid<Purpose>> {
279280
"std::size_t is neither 8 nor 4 bytes wide.");
280281

281282
if (sizeof(std::size_t) == 8) {
282-
const auto* ptr = reinterpret_cast<const std::uint64_t*>(uuid.value);
283+
const auto* ptr = reinterpret_cast<const std::uint64_t*>(uuid.value.data());
283284
return ptr[0] ^ ptr[1];
284285
} else {
285-
const auto* ptr = reinterpret_cast<const std::uint32_t*>(uuid.value);
286+
const auto* ptr = reinterpret_cast<const std::uint32_t*>(uuid.value.data());
286287
return ptr[0] ^ ptr[1] ^ ptr[2] ^ ptr[3];
287288
}
288289
}

tools/visualization/AriaViewer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <iostream>
2828

2929
// font defined in pangolin
30-
extern const unsigned char AnonymousPro_ttf[];
30+
extern const unsigned char AnonymousPro_ttf[]; // NOLINT(modernize-avoid-c-arrays)
3131

3232
using namespace projectaria::tools::data_provider;
3333
using namespace projectaria::tools::calibration;

0 commit comments

Comments
 (0)