felipecrv commented on code in PR #41956:
URL: https://github.com/apache/arrow/pull/41956#discussion_r1637316138
##########
cpp/src/arrow/array/array_nested.cc:
##########
@@ -847,30 +847,32 @@ Result<std::shared_ptr<Array>>
MapArray::FromArraysInternal(
const auto& typed_offsets = checked_cast<const OffsetArrayType&>(*offsets);
BufferVector buffers;
- int64_t null_count;
- if (null_bitmap != nullptr) {
- buffers = BufferVector({std::move(null_bitmap), typed_offsets.values()});
- null_count = null_bitmap->size();
- } else {
- buffers = BufferVector({null_bitmap, typed_offsets.values()});
- null_count = 0;
+ buffers.resize(2);
+ int64_t null_count = 0;
+ if (null_bitmap) {
+ buffers[0] = std::move(null_bitmap);
+ null_count = kUnknownNullCount;
}
+ buffers[1] = typed_offsets.values();
return std::make_shared<MapArray>(type, offsets->length() - 1,
std::move(buffers), keys,
items, /*null_count=*/null_count,
offsets->offset());
}
-Result<std::shared_ptr<Array>> MapArray::FromArrays(
- const std::shared_ptr<Array>& offsets, const std::shared_ptr<Array>& keys,
- const std::shared_ptr<Array>& items, MemoryPool* pool,
- const std::shared_ptr<Buffer>& null_bitmap) {
+Result<std::shared_ptr<Array>> MapArray::FromArrays(const
std::shared_ptr<Array>& offsets,
+ const
std::shared_ptr<Array>& keys,
+ const
std::shared_ptr<Array>& items,
+ MemoryPool* pool,
+ std::shared_ptr<Buffer>
null_bitmap) {
return FromArraysInternal(std::make_shared<MapType>(keys->type(),
items->type()),
offsets, keys, items, pool, null_bitmap);
}
-Result<std::shared_ptr<Array>> MapArray::FromArrays(
- std::shared_ptr<DataType> type, const std::shared_ptr<Array>& offsets,
- const std::shared_ptr<Array>& keys, const std::shared_ptr<Array>& items,
- MemoryPool* pool, const std::shared_ptr<Buffer>& null_bitmap) {
+Result<std::shared_ptr<Array>> MapArray::FromArrays(std::shared_ptr<DataType>
type,
+ const
std::shared_ptr<Array>& offsets,
+ const
std::shared_ptr<Array>& keys,
+ const
std::shared_ptr<Array>& items,
+ MemoryPool* pool,
+ std::shared_ptr<Buffer>
null_bitmap) {
Review Comment:
`move` is tricky 😬 and misnamed. It doesn't really move anything
(shockingly), it casts an l-value into an r-value. l-values are expressions
that can be on the left of an assignment and r-values only the right.
`l-value = r-value;`
Concretely:
```cpp
str = std::string{"abc"};
// std::string{"abc"} will construct a temp string
// which will be moved into str because it's an r-value
// But if you were to assign into `str` from an l-value called `abc`...
auto abc = std::string{"abc"};
// ^ l-value ^ r-value
str = abc;
// ^ l-value ^ an l-value as well
// after `str = abc`, `str` becomes a copy of abc and
// abc remains allocated, but if you do
str = std::move(abc);
// ^ l-value ^ r-value
// then by using `std::move` you're casting `abc` so that
// the operator `=` can consume it's contents. So the move
// only really happens at the moment the functions implementing
// = runs.
```
This is why you have to keep `std::move`ing the values until they reach a
point where they are stored on something (an l-value).
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]