| 1085 | } |
| 1086 | |
| 1087 | std::shared_ptr<Array> StructArray::field(int i) const { |
| 1088 | // Atomic ops on std::shared_ptr<T> are deprecated in C++20. They should be |
| 1089 | // replaced with std::atomic<std::shared_ptr<T>> but not all C++ standard |
| 1090 | // libraries implement it yet. :-/ |
| 1091 | ARROW_SUPPRESS_DEPRECATION_WARNING |
| 1092 | std::shared_ptr<Array> result = std::atomic_load(&impl_->boxed_fields_[i]); |
| 1093 | ARROW_UNSUPPRESS_DEPRECATION_WARNING |
| 1094 | if (result) { |
| 1095 | return result; |
| 1096 | } |
| 1097 | std::shared_ptr<ArrayData> field_data; |
| 1098 | if (data_->offset != 0 || data_->child_data[i]->length != data_->length) { |
| 1099 | field_data = data_->child_data[i]->Slice(data_->offset, data_->length); |
| 1100 | } else { |
| 1101 | field_data = data_->child_data[i]; |
| 1102 | } |
| 1103 | result = MakeArray(field_data); |
| 1104 | // Check if some other thread inserted the array in the meantime and return |
| 1105 | // that in that case. |
| 1106 | std::shared_ptr<Array> expected = nullptr; |
| 1107 | ARROW_SUPPRESS_DEPRECATION_WARNING |
| 1108 | const bool update_successful = |
| 1109 | std::atomic_compare_exchange_strong(&impl_->boxed_fields_[i], &expected, result); |
| 1110 | ARROW_UNSUPPRESS_DEPRECATION_WARNING |
| 1111 | if (!update_successful) { |
| 1112 | result = std::move(expected); |
| 1113 | } |
| 1114 | return result; |
| 1115 | } |
| 1116 | |
| 1117 | std::shared_ptr<Array> StructArray::GetFieldByName(const std::string& name) const { |
| 1118 | int i = struct_type()->GetFieldIndex(name); |