Skip to content

Commit 66a68ce

Browse files
committed
Return errors immediately instead of using goto
1 parent 86162aa commit 66a68ce

File tree

6 files changed

+89
-145
lines changed

6 files changed

+89
-145
lines changed

src/arm64/dom_parser_implementation.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,12 @@ WARN_UNUSED bool implementation::validate_utf8(const char *buf, size_t len) cons
144144
}
145145

146146
WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept {
147-
error_code result = stage2::parse_structurals<false>(*this, _doc);
148-
if (result) { return result; }
147+
if (auto error = stage2::parse_structurals<false>(*this, _doc)) { return error; }
149148

150149
// If we didn't make it to the end, it's an error
151150
if ( next_structural_index != n_structural_indexes ) {
152151
logger::log_string("More than one JSON value at the root of the document, or extra characters at the end of the JSON!");
153-
return error = TAPE_ERROR;
152+
return TAPE_ERROR;
154153
}
155154

156155
return SUCCESS;
@@ -161,8 +160,8 @@ WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_do
161160
}
162161

163162
WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept {
164-
error_code err = stage1(_buf, _len, false);
165-
if (err) { return err; }
163+
auto error = stage1(_buf, _len, false);
164+
if (error) { return error; }
166165
return stage2(_doc);
167166
}
168167

src/fallback/dom_parser_implementation.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,12 @@ namespace {
321321
namespace SIMDJSON_IMPLEMENTATION {
322322

323323
WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept {
324-
error_code result = stage2::parse_structurals<false>(*this, _doc);
325-
if (result) { return result; }
324+
if (auto error = stage2::parse_structurals<false>(*this, _doc)) { return error; }
326325

327326
// If we didn't make it to the end, it's an error
328327
if ( next_structural_index != n_structural_indexes ) {
329328
logger::log_string("More than one JSON value at the root of the document, or extra characters at the end of the JSON!");
330-
return error = TAPE_ERROR;
329+
return TAPE_ERROR;
331330
}
332331

333332
return SUCCESS;
@@ -338,8 +337,8 @@ WARN_UNUSED error_code dom_parser_implementation::stage2_next(dom::document &_do
338337
}
339338

340339
WARN_UNUSED error_code dom_parser_implementation::parse(const uint8_t *_buf, size_t _len, dom::document &_doc) noexcept {
341-
error_code err = stage1(_buf, _len, false);
342-
if (err) { return err; }
340+
auto error = stage1(_buf, _len, false);
341+
if (error) { return error; }
343342
return stage2(_doc);
344343
}
345344

src/generic/dom_parser_implementation.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ class dom_parser_implementation final : public internal::dom_parser_implementati
2828
size_t len{0};
2929
/** Document passed to stage 2 */
3030
dom::document *doc{};
31-
/** Error code (TODO remove, this is not even used, we just set it so the g++ optimizer doesn't get confused) */
32-
error_code error{UNINITIALIZED};
3331

3432
really_inline dom_parser_implementation();
3533
dom_parser_implementation(const dom_parser_implementation &) = delete;

0 commit comments

Comments
 (0)