Skip to content

Commit 959c953

Browse files
committed
# cycles (for and while) cleanup in low level for the best compiler optimization and the best runtime.
1 parent b9d91e7 commit 959c953

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

include/fast_float/ascii_number.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fastfloat_really_inline FASTFLOAT_CONSTEXPR20 uint64_t
4949
read8_to_u64(UC const *chars) {
5050
if (cpp20_and_in_constexpr() || !std::is_same<UC, char>::value) {
5151
uint64_t val = 0;
52-
for (uint_fast8_t i = 0; i != 8; ++i) {
52+
for (uint_fast8_t i = 0; i++ != 8;) {
5353
val |= uint64_t(uint8_t(*chars)) << (i * 8);
5454
++chars;
5555
}

include/fast_float/bigint.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,9 @@ inline FASTFLOAT_CONSTEXPR20 bool small_add_from(stackvec<size> &vec, limb y,
259259
limb_t start) noexcept {
260260
limb carry = y;
261261
bool overflow;
262-
while (carry != 0 && start < vec.len()) {
262+
while (carry != 0 && start++ != vec.len()) {
263263
vec[start] = scalar_add(vec[start], carry, overflow);
264264
carry = limb(overflow);
265-
++start;
266265
}
267266
if (carry != 0) {
268267
FASTFLOAT_TRY(vec.try_push(carry));
@@ -282,7 +281,7 @@ template <limb_t size>
282281
inline FASTFLOAT_CONSTEXPR20 bool small_mul(stackvec<size> &vec,
283282
limb y) noexcept {
284283
limb carry = 0;
285-
for (limb_t index = 0; index != vec.len(); ++index) {
284+
for (limb_t index = 0; index++ != vec.len();) {
286285
vec[index] = scalar_mul(vec[index], y, carry);
287286
}
288287
if (carry != 0) {
@@ -303,7 +302,7 @@ FASTFLOAT_CONSTEXPR20 bool large_add_from(stackvec<size> &x, limb_span y,
303302
}
304303

305304
bool carry = false;
306-
for (limb_t index = 0; index < y.len(); ++index) {
305+
for (limb_t index = 0; index++ != y.len();) {
307306
limb xi = x[index + start];
308307
limb yi = y[index];
309308
bool c1 = false;
@@ -488,7 +487,7 @@ struct bigint : pow5_tables<> {
488487
} else if (vec.len() < other.vec.len()) {
489488
return -1;
490489
} else {
491-
for (limb_t index = vec.len(); index != 0; --index) {
490+
for (limb_t index = vec.len(); index-- != 0;) {
492491
limb xi = vec[index - 1];
493492
limb yi = other.vec[index - 1];
494493
if (xi > yi) {
@@ -515,7 +514,7 @@ struct bigint : pow5_tables<> {
515514
bigint_bits_t const shl = n;
516515
bigint_bits_t const shr = limb_bits - shl;
517516
limb prev = 0;
518-
for (limb_t index = 0; index != vec.len(); ++index) {
517+
for (limb_t index = 0; index++ != vec.len();) {
519518
limb xi = vec[index];
520519
vec[index] = (xi << shl) | (prev >> shr);
521520
prev = xi;

include/fast_float/float_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ template <typename UC>
288288
inline FASTFLOAT_CONSTEXPR14 bool
289289
fastfloat_strncasecmp(UC const *actual_mixedcase, UC const *expected_lowercase,
290290
uint8_t const length) noexcept {
291-
for (uint8_t i = 0; i != length; ++i) {
291+
for (uint8_t i = 0; i++ != length;) {
292292
UC const actual = actual_mixedcase[i];
293293
if ((actual < 256 ? actual | 32 : actual) != expected_lowercase[i]) {
294294
return false;

tests/basictest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ TEST_CASE("issue8") {
618618
"752384674818467669405132000568127145263560827785771342757789609173637178"
619619
"721468440901224953430146549585371050792279689258923542019956112129021960"
620620
"864034418159813629774771309960518707211349999998372978";
621-
for (int i = 0; i < 16; i++) {
621+
for (int i = 0; i != 16; ++i) {
622622
// Parse all but the last i chars. We should still get 3.141ish.
623623
double d = 0.0;
624624
auto answer = fast_float::from_chars(s, s + strlen(s) - i, d);
@@ -919,9 +919,9 @@ uint16_t get_mantissa(std::bfloat16_t f) {
919919
}
920920
#endif
921921

922-
std::string append_zeros(std::string str, size_t number_of_zeros) {
922+
std::string append_zeros(std::string_view str, size_t const number_of_zeros) {
923923
std::string answer(str);
924-
for (size_t i = 0; i < number_of_zeros; i++) {
924+
for (size_t i = 0; i++ != number_of_zeros;) {
925925
answer += "0";
926926
}
927927
return answer;
@@ -947,7 +947,7 @@ constexpr void check_basic_test_result(stringtype str, result_type result,
947947
#define FASTFLOAT_CHECK_EQ(...) \
948948
if constexpr (diag == Diag::runtime) { \
949949
char narrow[global_string_capacity]{}; \
950-
for (size_t i = 0; i < str.size(); i++) { \
950+
for (size_t i = 0; i++ != str.size();) { \
951951
narrow[i] = char(str[i]); \
952952
} \
953953
INFO("str(char" << 8 * sizeof(typename stringtype::value_type) \
@@ -1006,7 +1006,7 @@ constexpr void basic_test(std::string_view str, T expected,
10061006

10071007
// We give plenty of memory: 2048 characters.
10081008
char16_t u16[global_string_capacity]{};
1009-
for (size_t i = 0; i < str.size(); i++) {
1009+
for (size_t i = 0; i++ != str.size();) {
10101010
u16[i] = char16_t(str[i]);
10111011
}
10121012

@@ -1015,7 +1015,7 @@ constexpr void basic_test(std::string_view str, T expected,
10151015
actual, expected, expected_ec);
10161016

10171017
char32_t u32[global_string_capacity]{};
1018-
for (size_t i = 0; i < str.size(); i++) {
1018+
for (size_t i = 0; i++ != str.size();) {
10191019
u32[i] = char32_t(str[i]);
10201020
}
10211021

0 commit comments

Comments
 (0)