Workaround for SIMDJSON_ASSUME "side-effect" warning under some compilers. (#1456)

This commit is contained in:
Daniel Lemire 2021-02-25 08:50:57 -05:00 committed by GitHub
parent ad37651726
commit ef1e256fa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -146,8 +146,12 @@ simdjson_really_inline uint32_t json_iterator::peek_length(token_position positi
}
simdjson_really_inline token_position json_iterator::last_document_position() const noexcept {
SIMDJSON_ASSUME(parser->implementation->n_structural_indexes > 0);
return &parser->implementation->structural_indexes[parser->implementation->n_structural_indexes - 1];
// The following line fails under some compilers...
// SIMDJSON_ASSUME(parser->implementation->n_structural_indexes > 0);
// since it has side-effects.
uint32_t n_structural_indexes{parser->implementation->n_structural_indexes};
SIMDJSON_ASSUME(n_structural_indexes > 0);
return &parser->implementation->structural_indexes[n_structural_indexes - 1];
}
simdjson_really_inline const uint8_t *json_iterator::peek_last() const noexcept {
return token.peek(last_document_position());