Skip to content

Commit 88d82b7

Browse files
[libc] fix more readability-identifier-naming lints (#83914)
Found via: $ ninja -k2000 libc-lint 2>&1 | grep readability-identifier-naming Auto fixed via: $ clang-tidy -p build/compile_commands.json \ -checks="-*,readability-identifier-naming" \ <filename> --fix This doesn't fix all instances, just the obvious simple cases where it makes sense to change the identifier names. Subsequent PRs will fix up the stragglers.
1 parent ec7062d commit 88d82b7

File tree

9 files changed

+109
-107
lines changed

9 files changed

+109
-107
lines changed

libc/src/__support/blockstore.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class BlockStore {
4545
struct Pair {
4646
Block *first, *second;
4747
};
48-
Pair getLastBlocks() {
48+
Pair get_last_blocks() {
4949
if (REVERSE_ORDER)
5050
return {current, current->next};
5151
Block *prev = nullptr;
@@ -56,20 +56,20 @@ class BlockStore {
5656
return {curr, prev};
5757
}
5858

59-
Block *getLastBlock() { return getLastBlocks().first; }
59+
Block *get_last_block() { return get_last_blocks().first; }
6060

6161
public:
6262
constexpr BlockStore() = default;
6363
~BlockStore() = default;
6464

65-
class iterator {
65+
class Iterator {
6666
Block *block;
6767
size_t index;
6868

6969
public:
70-
constexpr iterator(Block *b, size_t i) : block(b), index(i) {}
70+
constexpr Iterator(Block *b, size_t i) : block(b), index(i) {}
7171

72-
iterator &operator++() {
72+
Iterator &operator++() {
7373
if (REVERSE_ORDER) {
7474
if (index == 0)
7575
return *this;
@@ -98,11 +98,11 @@ class BlockStore {
9898
return *reinterpret_cast<T *>(block->data + sizeof(T) * true_index);
9999
}
100100

101-
bool operator==(const iterator &rhs) const {
101+
bool operator==(const Iterator &rhs) const {
102102
return block == rhs.block && index == rhs.index;
103103
}
104104

105-
bool operator!=(const iterator &rhs) const {
105+
bool operator!=(const Iterator &rhs) const {
106106
return block != rhs.block || index != rhs.index;
107107
}
108108
};
@@ -138,15 +138,15 @@ class BlockStore {
138138
}
139139

140140
T &back() {
141-
return *reinterpret_cast<T *>(getLastBlock()->data +
141+
return *reinterpret_cast<T *>(get_last_block()->data +
142142
sizeof(T) * (fill_count - 1));
143143
}
144144

145145
void pop_back() {
146146
fill_count--;
147147
if (fill_count || current == &first)
148148
return;
149-
auto [last, prev] = getLastBlocks();
149+
auto [last, prev] = get_last_blocks();
150150
if (REVERSE_ORDER) {
151151
LIBC_ASSERT(last == current);
152152
current = current->next;
@@ -162,18 +162,18 @@ class BlockStore {
162162

163163
bool empty() const { return current == &first && !fill_count; }
164164

165-
iterator begin() {
165+
Iterator begin() {
166166
if (REVERSE_ORDER)
167-
return iterator(current, fill_count);
167+
return Iterator(current, fill_count);
168168
else
169-
return iterator(&first, 0);
169+
return Iterator(&first, 0);
170170
}
171171

172-
iterator end() {
172+
Iterator end() {
173173
if (REVERSE_ORDER)
174-
return iterator(&first, 0);
174+
return Iterator(&first, 0);
175175
else
176-
return iterator(current, fill_count);
176+
return Iterator(current, fill_count);
177177
}
178178
};
179179

libc/src/__support/integer_to_string.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ template <typename T, typename Fmt = radix::Dec> class IntegerToString {
166166
static_assert(cpp::is_integral_v<T>);
167167

168168
LIBC_INLINE static constexpr size_t compute_buffer_size() {
169-
constexpr auto max_digits = []() -> size_t {
169+
constexpr auto MAX_DIGITS = []() -> size_t {
170170
// We size the string buffer for base 10 using an approximation algorithm:
171171
//
172172
// size = ceil(sizeof(T) * 5 / 2)
@@ -188,19 +188,19 @@ template <typename T, typename Fmt = radix::Dec> class IntegerToString {
188188
// For other bases, we approximate by rounding down to the nearest power
189189
// of two base, since the space needed is easy to calculate and it won't
190190
// overestimate by too much.
191-
constexpr auto floor_log_2 = [](size_t num) -> size_t {
191+
constexpr auto FLOOR_LOG_2 = [](size_t num) -> size_t {
192192
size_t i = 0;
193193
for (; num > 1; num /= 2)
194194
++i;
195195
return i;
196196
};
197-
constexpr size_t BITS_PER_DIGIT = floor_log_2(Fmt::BASE);
197+
constexpr size_t BITS_PER_DIGIT = FLOOR_LOG_2(Fmt::BASE);
198198
return ((sizeof(T) * 8 + (BITS_PER_DIGIT - 1)) / BITS_PER_DIGIT);
199199
};
200-
constexpr size_t digit_size = cpp::max(max_digits(), Fmt::MIN_DIGITS);
201-
constexpr size_t sign_size = Fmt::BASE == 10 ? 1 : 0;
202-
constexpr size_t prefix_size = Fmt::PREFIX ? 2 : 0;
203-
return digit_size + sign_size + prefix_size;
200+
constexpr size_t DIGIT_SIZE = cpp::max(MAX_DIGITS(), Fmt::MIN_DIGITS);
201+
constexpr size_t SIGN_SIZE = Fmt::BASE == 10 ? 1 : 0;
202+
constexpr size_t PREFIX_SIZE = Fmt::PREFIX ? 2 : 0;
203+
return DIGIT_SIZE + SIGN_SIZE + PREFIX_SIZE;
204204
}
205205

206206
static constexpr size_t BUFFER_SIZE = compute_buffer_size();

libc/src/__support/math_extras.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ namespace LIBC_NAMESPACE {
2222
template <typename T, size_t count>
2323
LIBC_INLINE constexpr T mask_trailing_ones() {
2424
static_assert(cpp::is_unsigned_v<T>);
25-
constexpr unsigned t_bits = CHAR_BIT * sizeof(T);
26-
static_assert(count <= t_bits && "Invalid bit index");
25+
constexpr unsigned T_BITS = CHAR_BIT * sizeof(T);
26+
static_assert(count <= T_BITS && "Invalid bit index");
2727
// It's important not to initialize T with -1, since T may be BigInt which
2828
// will take -1 as a uint64_t and only initialize the low 64 bits.
29-
constexpr T all_zeroes(0);
30-
constexpr T all_ones(~all_zeroes); // bitwise NOT performs integer promotion.
31-
return count == 0 ? 0 : (all_ones >> (t_bits - count));
29+
constexpr T ALL_ZEROES(0);
30+
constexpr T ALL_ONES(~ALL_ZEROES); // bitwise NOT performs integer promotion.
31+
return count == 0 ? 0 : (ALL_ONES >> (T_BITS - count));
3232
}
3333

3434
// Create a bitmask with the count left-most bits set to 1, and all other bits
3535
// set to 0. Only unsigned types are allowed.
3636
template <typename T, size_t count>
3737
LIBC_INLINE constexpr T mask_leading_ones() {
38-
constexpr T mask(mask_trailing_ones<T, CHAR_BIT * sizeof(T) - count>());
39-
return T(~mask); // bitwise NOT performs integer promotion.
38+
constexpr T MASK(mask_trailing_ones<T, CHAR_BIT * sizeof(T) - count>());
39+
return T(~MASK); // bitwise NOT performs integer promotion.
4040
}
4141

4242
// Add with carry

libc/src/math/generic/hypotf.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ LLVM_LIBC_FUNCTION(float, hypotf, (float x, float y)) {
4848
// Correct rounding.
4949
double r_sq = result.get_val() * result.get_val();
5050
double diff = sum_sq - r_sq;
51-
constexpr uint64_t mask = 0x0000'0000'3FFF'FFFFULL;
52-
uint64_t lrs = result.uintval() & mask;
51+
constexpr uint64_t MASK = 0x0000'0000'3FFF'FFFFULL;
52+
uint64_t lrs = result.uintval() & MASK;
5353

5454
if (lrs == 0x0000'0000'1000'0000ULL && err < diff) {
5555
result.set_uintval(result.uintval() | 1ULL);

libc/src/string/memory_utils/op_generic.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ template <typename T> T load(CPtr src) {
9595
return ::LIBC_NAMESPACE::load<T>(src);
9696
} else if constexpr (is_array_v<T>) {
9797
using value_type = typename T::value_type;
98-
T Value;
99-
for (size_t I = 0; I < array_size_v<T>; ++I)
100-
Value[I] = load<value_type>(src + (I * sizeof(value_type)));
101-
return Value;
98+
T value;
99+
for (size_t i = 0; i < array_size_v<T>; ++i)
100+
value[i] = load<value_type>(src + (i * sizeof(value_type)));
101+
return value;
102102
}
103103
}
104104

@@ -108,8 +108,8 @@ template <typename T> void store(Ptr dst, T value) {
108108
::LIBC_NAMESPACE::store<T>(dst, value);
109109
} else if constexpr (is_array_v<T>) {
110110
using value_type = typename T::value_type;
111-
for (size_t I = 0; I < array_size_v<T>; ++I)
112-
store<value_type>(dst + (I * sizeof(value_type)), value[I]);
111+
for (size_t i = 0; i < array_size_v<T>; ++i)
112+
store<value_type>(dst + (i * sizeof(value_type)), value[i]);
113113
}
114114
}
115115

@@ -118,11 +118,11 @@ template <typename T> T splat(uint8_t value) {
118118
if constexpr (is_scalar_v<T>)
119119
return T(~0) / T(0xFF) * T(value);
120120
else if constexpr (is_vector_v<T>) {
121-
T Out;
121+
T out;
122122
// This for loop is optimized out for vector types.
123123
for (size_t i = 0; i < sizeof(T); ++i)
124-
Out[i] = value;
125-
return Out;
124+
out[i] = value;
125+
return out;
126126
}
127127
}
128128

@@ -140,8 +140,8 @@ template <typename T> struct Memset {
140140
} else if constexpr (is_array_v<T>) {
141141
using value_type = typename T::value_type;
142142
const auto Splat = splat<value_type>(value);
143-
for (size_t I = 0; I < array_size_v<T>; ++I)
144-
store<value_type>(dst + (I * sizeof(value_type)), Splat);
143+
for (size_t i = 0; i < array_size_v<T>; ++i)
144+
store<value_type>(dst + (i * sizeof(value_type)), Splat);
145145
}
146146
}
147147

libc/src/string/memory_utils/op_x86.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040
namespace LIBC_NAMESPACE::x86 {
4141

4242
// A set of constants to check compile time features.
43-
LIBC_INLINE_VAR constexpr bool kSse2 = LLVM_LIBC_IS_DEFINED(__SSE2__);
44-
LIBC_INLINE_VAR constexpr bool kSse41 = LLVM_LIBC_IS_DEFINED(__SSE4_1__);
45-
LIBC_INLINE_VAR constexpr bool kAvx = LLVM_LIBC_IS_DEFINED(__AVX__);
46-
LIBC_INLINE_VAR constexpr bool kAvx2 = LLVM_LIBC_IS_DEFINED(__AVX2__);
47-
LIBC_INLINE_VAR constexpr bool kAvx512F = LLVM_LIBC_IS_DEFINED(__AVX512F__);
48-
LIBC_INLINE_VAR constexpr bool kAvx512BW = LLVM_LIBC_IS_DEFINED(__AVX512BW__);
43+
LIBC_INLINE_VAR constexpr bool K_SSE2 = LLVM_LIBC_IS_DEFINED(__SSE2__);
44+
LIBC_INLINE_VAR constexpr bool K_SSE41 = LLVM_LIBC_IS_DEFINED(__SSE4_1__);
45+
LIBC_INLINE_VAR constexpr bool K_AVX = LLVM_LIBC_IS_DEFINED(__AVX__);
46+
LIBC_INLINE_VAR constexpr bool K_AVX2 = LLVM_LIBC_IS_DEFINED(__AVX2__);
47+
LIBC_INLINE_VAR constexpr bool K_AVX512_F = LLVM_LIBC_IS_DEFINED(__AVX512F__);
48+
LIBC_INLINE_VAR constexpr bool K_AVX512_BW = LLVM_LIBC_IS_DEFINED(__AVX512BW__);
4949

5050
///////////////////////////////////////////////////////////////////////////////
5151
// Memcpy repmovsb implementation

libc/src/string/memory_utils/utils.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ LIBC_INLINE MemcmpReturnType cmp_neq_uint64_t(uint64_t a, uint64_t b) {
205205
// Loads bytes from memory (possibly unaligned) and materializes them as
206206
// type.
207207
template <typename T> LIBC_INLINE T load(CPtr ptr) {
208-
T Out;
209-
memcpy_inline<sizeof(T)>(&Out, ptr);
210-
return Out;
208+
T out;
209+
memcpy_inline<sizeof(T)>(&out, ptr);
210+
return out;
211211
}
212212

213213
// Stores a value of type T in memory (possibly unaligned).
@@ -228,12 +228,12 @@ LIBC_INLINE ValueType load_aligned(CPtr src) {
228228
static_assert(sizeof(ValueType) >= (sizeof(T) + ... + sizeof(TS)));
229229
const ValueType value = load<T>(assume_aligned<sizeof(T)>(src));
230230
if constexpr (sizeof...(TS) > 0) {
231-
constexpr size_t shift = sizeof(T) * 8;
231+
constexpr size_t SHIFT = sizeof(T) * 8;
232232
const ValueType next = load_aligned<ValueType, TS...>(src + sizeof(T));
233233
if constexpr (Endian::IS_LITTLE)
234-
return value | (next << shift);
234+
return value | (next << SHIFT);
235235
else if constexpr (Endian::IS_BIG)
236-
return (value << shift) | next;
236+
return (value << SHIFT) | next;
237237
else
238238
static_assert(cpp::always_false<T>, "Invalid endianness");
239239
} else {
@@ -261,16 +261,16 @@ LIBC_INLINE auto load64_aligned(CPtr src, size_t offset) {
261261
template <typename ValueType, typename T, typename... TS>
262262
LIBC_INLINE void store_aligned(ValueType value, Ptr dst) {
263263
static_assert(sizeof(ValueType) >= (sizeof(T) + ... + sizeof(TS)));
264-
constexpr size_t shift = sizeof(T) * 8;
264+
constexpr size_t SHIFT = sizeof(T) * 8;
265265
if constexpr (Endian::IS_LITTLE) {
266266
store<T>(assume_aligned<sizeof(T)>(dst), value & ~T(0));
267267
if constexpr (sizeof...(TS) > 0)
268-
store_aligned<ValueType, TS...>(value >> shift, dst + sizeof(T));
268+
store_aligned<ValueType, TS...>(value >> SHIFT, dst + sizeof(T));
269269
} else if constexpr (Endian::IS_BIG) {
270270
constexpr size_t OFFSET = (0 + ... + sizeof(TS));
271271
store<T>(assume_aligned<sizeof(T)>(dst + OFFSET), value & ~T(0));
272272
if constexpr (sizeof...(TS) > 0)
273-
store_aligned<ValueType, TS...>(value >> shift, dst);
273+
store_aligned<ValueType, TS...>(value >> SHIFT, dst);
274274
} else {
275275
static_assert(cpp::always_false<T>, "Invalid endianness");
276276
}

0 commit comments

Comments
 (0)