pitrou commented on code in PR #14100:
URL: https://github.com/apache/arrow/pull/14100#discussion_r970950406


##########
cpp/src/arrow/json/parser.cc:
##########
@@ -749,9 +746,16 @@ class HandlerBase : public BlockParser,
   /// there is no field with that name
   bool SetFieldBuilder(string_view key, bool* duplicate_keys) {
     auto parent = Cast<Kind::kObject>(builder_stack_.back());
-    field_index_ = parent->GetFieldIndex(std::string(key));
-    if (ARROW_PREDICT_FALSE(field_index_ == -1)) {
-      return false;
+    DCHECK(field_index_ >= -1 && field_index_ < parent->num_fields());
+    // Predict that this field is known and immediately follows the last one. 
Otherwise,
+    // fall back to the hash table lookup
+    ++field_index_;
+    if (ARROW_PREDICT_FALSE(field_index_ == parent->num_fields() ||
+                            key != parent->field_name(field_index_))) {
+      field_index_ = parent->GetFieldIndex(std::string(key));

Review Comment:
   Note that a separate optimization would be to avoid creating a new 
`std::string` when looking up the field index (for example by having a separate 
vector of field names and using a `std::unordered_map<string_view, int>` for 
the actual lookup).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to