-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace usage of JsonArray::has_more
with range-based loops.
#36227
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The current code would just skip the array entry if it was neither a string nor an object. There is no indication to the modder that their data has been ignored. The new code will trigger an error instead. The modder will know about the invalid format.
The code would always use the first entry of the parent array (`trait`) instead of the that of the subarray. It would however use the *second* value of the subarray and skip the first one. Makes no sense.
There is a check for whether the array has more entries. That one will catch empty array.
It checks the same thing essentially: that there is at least one intensity level defined.
Change `requirement_data::load_obj_list` to take a reference to const JsonArray. This allows to inline the code in the caller (the JsonArray instance does not need to be stored in a variable). Inside the function, change the loops to range-based loops over the array / the subarray. In turn, change the various `load` functions to accept `const JsonValue &` (entries of the array). The functions used to get the full array as reference and would extract the next element from it.
This allows to iterate over the array using a range-based lood.
Which can be used just like the stream. Also added a `JsonObject::get_member` function to get a specific member as `JsonValue`.
…nce. Which allows to iterate over the array using a range-based loop.
And use a range-based loop.
And iterate over it via a range-based loop.
The loop would previously read more data than there was storage reserved for (it could read more than `adv_inv_in_vehicle.size()` elements).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SUMMARY: None
Fixes a bug as well.
Changes a few functions to take a
const JsonValue &
instead of aJsonIn
stream.