Skip to content

Commit f9e2220

Browse files
committed
review of the fastfloat_strncasecmp3 fastfloat_strncasecmp5 fastfloat_strncasecmp and parse_infnan
1 parent 3b7dc1e commit f9e2220

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

include/fast_float/float_common.h

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ fastfloat_strncasecmp3(UC const *actual_mixedcase,
334334
}
335335
}
336336
} else {
337-
uint64_t val1, val2;
337+
uint64_t val1{0}, val2{0};
338338
uint64_t mask;
339339
FASTFLOAT_IF_CONSTEXPR17(sizeof(UC) == 1) { mask = 0x2020202020202020; }
340340
else FASTFLOAT_IF_CONSTEXPR17(sizeof(UC) == 2) {
@@ -344,15 +344,15 @@ fastfloat_strncasecmp3(UC const *actual_mixedcase,
344344
mask = 0x0000002000000020;
345345
}
346346
FASTFLOAT_IF_CONSTEXPR17(sizeof(UC) == 1 || sizeof(UC) == 2) {
347-
std::memcpy(&val1, actual_mixedcase, 3 * sizeof(UC));
348-
std::memcpy(&val2, expected_lowercase, 3 * sizeof(UC));
347+
::memcpy(&val1, actual_mixedcase, 3 * sizeof(UC));
348+
::memcpy(&val2, expected_lowercase, 3 * sizeof(UC));
349349
val1 |= mask;
350350
val2 |= mask;
351351
return val1 == val2;
352352
}
353353
else FASTFLOAT_IF_CONSTEXPR17(sizeof(UC) == 4) {
354-
std::memcpy(&val1, actual_mixedcase, 2 * sizeof(UC));
355-
std::memcpy(&val2, expected_lowercase, 2 * sizeof(UC));
354+
::memcpy(&val1, actual_mixedcase, 2 * sizeof(UC));
355+
::memcpy(&val2, expected_lowercase, 2 * sizeof(UC));
356356
val1 |= mask;
357357
if (val1 != val2) {
358358
return false;
@@ -378,7 +378,7 @@ fastfloat_strncasecmp5(UC const *actual_mixedcase,
378378
}
379379
}
380380
} else {
381-
uint64_t val1, val2;
381+
uint64_t val1{0}, val2{0};
382382
FASTFLOAT_IF_CONSTEXPR17(sizeof(UC) == 1) {
383383
constexpr uint64_t mask = 0x2020202020202020;
384384
std::memcpy(&val1, actual_mixedcase, 5 * sizeof(UC));
@@ -413,9 +413,6 @@ fastfloat_strncasecmp5(UC const *actual_mixedcase,
413413
}
414414
return (actual_mixedcase[4] | 32) == (expected_lowercase[4]);
415415
}
416-
else {
417-
return false;
418-
}
419416
}
420417

421418
return true;
@@ -433,6 +430,7 @@ fastfloat_strncasecmp(UC const *actual_mixedcase, UC const *expected_lowercase,
433430
}
434431
}
435432
} else {
433+
uint64_t val1{0}, val2{0};
436434
uint64_t mask;
437435
FASTFLOAT_IF_CONSTEXPR17(sizeof(UC) == 1) { mask = 0x2020202020202020; }
438436
else FASTFLOAT_IF_CONSTEXPR17(sizeof(UC) == 2) {
@@ -441,16 +439,12 @@ fastfloat_strncasecmp(UC const *actual_mixedcase, UC const *expected_lowercase,
441439
else FASTFLOAT_IF_CONSTEXPR17(sizeof(UC) == 4) {
442440
mask = 0x0000002000000020;
443441
}
444-
else {
445-
return false;
446-
}
447442
constexpr uint_fast8_t sz{8 / (sizeof(UC))};
448-
for (uint_fast8_t i = 0; i != length; i += sz) {
449-
uint64_t val1{0};
450-
uint64_t val2{0};
443+
for (uint_fast8_t i = 0; i < length; i += sz) {
444+
val1 = val2 = 0;
451445
sz = std::min(sz, length - i);
452-
::memcpy(&val1, actual_mixedcase + i, sz * sizeof(UC));
453-
::memcpy(&val2, expected_lowercase + i, sz * sizeof(UC));
446+
std::memcpy(&val1, actual_mixedcase + i, sz * sizeof(UC));
447+
std::memcpy(&val2, expected_lowercase + i, sz * sizeof(UC));
454448
val1 |= mask;
455449
val2 |= mask;
456450
if (val1 != val2) {

include/fast_float/parse_number.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace fast_float {
1616
namespace detail {
1717
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
1818
/**
19-
* Special case +inf, -inf, nan, infinity, -infinity.
19+
* Special case inf, +inf, -inf, nan, infinity, -infinity.
2020
* The case comparisons could be made much faster given that we know that the
2121
* strings a null-free and fixed.
2222
**/
@@ -46,7 +46,7 @@ from_chars_result_t<UC>
4646
// Check for possible nan(n-char-seq-opt), C++17 20.19.3.7,
4747
// C11 7.20.1.3.3. At least MSVC produces nan(ind) and nan(snan).
4848
if (first != last && *first == UC('(')) {
49-
for (UC const *ptr = first + 1; ptr != last; ++ptr) {
49+
for (auto const *ptr = first + 1; ptr != last; ++ptr) {
5050
if (*ptr == UC(')')) {
5151
answer.ptr = ptr + 1; // valid nan(n-char-seq-opt)
5252
break;

0 commit comments

Comments
 (0)