Commits


Benjamin Kietzman authored and GitHub committed 7a5f57f2122
GH-36367: [C++] Add a zipped range utility (#36393) ### Rationale for this change We write a lot of loops over parallel ranges. This function is a proven pattern improving code clarity in other languages ### What changes are included in this PR? A zip utility is added which simplifies writing loops over parallel ranges. ```diff @@ -1118,9 +1118,8 @@ Status GetFieldsFromArray(const RjArray& json_fields, FieldPosition parent_pos, DictionaryMemo* dictionary_memo, std::vector<std::shared_ptr<Field>>* fields) { fields->resize(json_fields.Size()); - for (rj::SizeType i = 0; i < json_fields.Size(); ++i) { - RETURN_NOT_OK(GetField(json_fields[i], parent_pos.child(static_cast<int>(i)), - dictionary_memo, &(*fields)[i])); + for (auto [json_field, field, i] : Zip(json_fields, *fields, Enumerate<int>)) { + RETURN_NOT_OK(GetField(json_field, parent_pos.child(i), dictionary_memo, &field)); } return Status::OK(); } ``` Some(most) of the loops in json_internal.cc are rewritten to showcase usage. ### Are these changes tested? Yes, in `range_test.cc`. ### Are there any user-facing changes? No, this is an internal utility. * Closes: #36367 Authored-by: Benjamin Kietzman <bengilgit@gmail.com> Signed-off-by: Antoine Pitrou <antoine@python.org>