Skip to content

Commit 497e65b

Browse files
committed
* Added separate config macros FASTFLOAT_ISNOT_CHECKED_BOUNDS.
1 parent c8e4d89 commit 497e65b

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,15 +380,17 @@ int main() {
380380

381381
## You also can also use some additional options (currently only configure by macroses):
382382

383-
There is a really common use case in mathematical and other abstract syntax tree (AST) like parsers,
384-
that already process sign and all other symbols before any number by itself. In this case you can
385-
use FastFloat for only parse positive numbers in all supported formats with macros
386-
`FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN`, that significantly reduce the code size and improve
387-
performance. Additionally you can use macros `FASTFLOAT_ONLY_ROUNDS_TO_NEAREST_SUPPORTED` if you
388-
only uneed `FE_TONEAREST` rounding mode in the parsing: this option is also improve performance a bit.
383+
There is a really common use case in mathematical and other abstract syntax tree (AST)-like parsers that already processes
384+
the sign and all other symbols before any number by itself. In this case you can use FastFloat to only parse positive numbers
385+
in all supported formats with macros `FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN`, which significantly reduce the code size
386+
and improve performance. You also can use macros `FASTFLOAT_ISNOT_CHECKED_BOUNDS` if your code already checks bounds;
387+
it's very likely because all parsers need to check the first character by itself before parsing. Additionally, you can use
388+
macros `FASTFLOAT_ONLY_ROUNDS_TO_NEAREST_SUPPORTED` if you only need `FE_TONEAREST` rounding mode in the parsing;
389+
this option also improves performance a bit and reduces code size.
389390

390391
```C++
391392
#define FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
393+
#define FASTFLOAT_ISNOT_CHECKED_BOUNDS
392394
#define FASTFLOAT_ONLY_ROUNDS_TO_NEAREST_SUPPORTED
393395
#include "fast_float/fast_float.h"
394396
#include <iostream>

include/fast_float/parse_number.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,16 @@ from_chars_float_advanced(UC const *first, UC const *last, T &value,
336336
++first;
337337
}
338338
}
339+
#endif
340+
#ifdef FASTFLOAT_ISNOT_CHECKED_BOUNDS
341+
// We are in parser code with external loop that checks bounds.
342+
FASTFLOAT_ASSUME(first < last);
343+
#else
339344
if (first == last) {
340345
answer.ec = std::errc::invalid_argument;
341346
answer.ptr = first;
342347
return answer;
343348
}
344-
#else
345-
// We are in parser code with external loop that checks bounds.
346-
FASTFLOAT_ASSUME(first < last);
347349
#endif
348350
parsed_number_string_t<UC> const pns =
349351
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
@@ -498,19 +500,19 @@ from_chars_int_advanced(UC const *first, UC const *last, T &value,
498500
static_assert(is_supported_char_type<UC>::value,
499501
"only char, wchar_t, char16_t and char32_t are supported");
500502

501-
#ifdef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
502-
// We are in parser code with external loop that checks bounds.
503-
FASTFLOAT_ASSUME(first < last);
504-
// base is already checked in the parse_options_t constructor.
505-
#else
503+
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
506504
if (chars_format_t(options.format & chars_format::skip_white_space)) {
507505
while ((first != last) && fast_float::is_space(*first)) {
508506
++first;
509507
}
510508
}
509+
#endif
510+
#ifdef FASTFLOAT_ISNOT_CHECKED_BOUNDS
511+
// We are in parser code with external loop that checks bounds.
512+
FASTFLOAT_ASSUME(first < last);
511513
#endif
512514
if (
513-
#ifndef FASTFLOAT_ONLY_POSITIVE_C_NUMBER_WO_INF_NAN
515+
#ifndef FASTFLOAT_ISNOT_CHECKED_BOUNDS
514516
first == last ||
515517
#endif
516518
options.base < 2 || options.base > 36) {

0 commit comments

Comments
 (0)