| 1125 | } |
| 1126 | |
| 1127 | std::shared_ptr<Array> StructArray::field(int i) const { |
| 1128 | // Atomic ops on std::shared_ptr<T> are deprecated in C++20. They should be |
| 1129 | // replaced with std::atomic<std::shared_ptr<T>> but not all C++ standard |
| 1130 | // libraries implement it yet. :-/ |
| 1131 | ARROW_SUPPRESS_DEPRECATION_WARNING |
| 1132 | std::shared_ptr<Array> result = std::atomic_load(&impl_->boxed_fields_[i]); |
| 1133 | ARROW_UNSUPPRESS_DEPRECATION_WARNING |
| 1134 | if (result) { |
| 1135 | return result; |
| 1136 | } |
| 1137 | std::shared_ptr<ArrayData> field_data; |
| 1138 | if (data_->offset != 0 || data_->child_data[i]->length != data_->length) { |
| 1139 | field_data = data_->child_data[i]->Slice(data_->offset, data_->length); |
| 1140 | } else { |
| 1141 | field_data = data_->child_data[i]; |
| 1142 | } |
| 1143 | result = MakeArray(field_data); |
| 1144 | // Check if some other thread inserted the array in the meantime and return |
| 1145 | // that in that case. |
| 1146 | std::shared_ptr<Array> expected = nullptr; |
| 1147 | ARROW_SUPPRESS_DEPRECATION_WARNING |
| 1148 | const bool update_successful = |
| 1149 | std::atomic_compare_exchange_strong(&impl_->boxed_fields_[i], &expected, result); |
| 1150 | ARROW_UNSUPPRESS_DEPRECATION_WARNING |
| 1151 | if (!update_successful) { |
| 1152 | result = std::move(expected); |
| 1153 | } |
| 1154 | return result; |
| 1155 | } |
| 1156 | |
| 1157 | std::shared_ptr<Array> StructArray::GetFieldByName(const std::string& name) const { |
| 1158 | int i = struct_type()->GetFieldIndex(name); |