Skip to content

Commit c28b1c9

Browse files
committed
[C++] Remove unnecessary copies of shared_ptr in Type::BOOL and Type::NA at GrouperImpl
1 parent 08175e5 commit c28b1c9

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

cpp/src/arrow/compute/row/grouper.cc

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -341,43 +341,44 @@ struct GrouperImpl : public Grouper {
341341
impl->ctx_ = ctx;
342342

343343
for (size_t i = 0; i < key_types.size(); ++i) {
344-
// TODO(wesm): eliminate this probably unneeded shared_ptr copy
345-
std::shared_ptr<DataType> key = key_types[i].GetSharedPtr();
344+
const auto& key_type = key_types[i];
346345

347-
if (key->id() == Type::BOOL) {
346+
if (key_type.id() == Type::BOOL) {
348347
impl->encoders_[i] = std::make_unique<internal::BooleanKeyEncoder>();
349348
continue;
350349
}
351350

352-
if (key->id() == Type::DICTIONARY) {
353-
impl->encoders_[i] =
354-
std::make_unique<internal::DictionaryKeyEncoder>(key, ctx->memory_pool());
351+
if (key_type.id() == Type::DICTIONARY) {
352+
impl->encoders_[i] = std::make_unique<internal::DictionaryKeyEncoder>(
353+
key_type.GetSharedPtr(), ctx->memory_pool());
355354
continue;
356355
}
357356

358-
if (is_fixed_width(key->id())) {
359-
impl->encoders_[i] = std::make_unique<internal::FixedWidthKeyEncoder>(key);
357+
if (is_fixed_width(key_type.id())) {
358+
impl->encoders_[i] =
359+
std::make_unique<internal::FixedWidthKeyEncoder>(key_type.GetSharedPtr());
360360
continue;
361361
}
362362

363-
if (is_binary_like(key->id())) {
364-
impl->encoders_[i] =
365-
std::make_unique<internal::VarLengthKeyEncoder<BinaryType>>(key);
363+
if (is_binary_like(key_type.id())) {
364+
impl->encoders_[i] = std::make_unique<internal::VarLengthKeyEncoder<BinaryType>>(
365+
key_type.GetSharedPtr());
366366
continue;
367367
}
368368

369-
if (is_large_binary_like(key->id())) {
369+
if (is_large_binary_like(key_type.id())) {
370370
impl->encoders_[i] =
371-
std::make_unique<internal::VarLengthKeyEncoder<LargeBinaryType>>(key);
371+
std::make_unique<internal::VarLengthKeyEncoder<LargeBinaryType>>(
372+
key_type.GetSharedPtr());
372373
continue;
373374
}
374375

375-
if (key->id() == Type::NA) {
376+
if (key_type.id() == Type::NA) {
376377
impl->encoders_[i] = std::make_unique<internal::NullKeyEncoder>();
377378
continue;
378379
}
379380

380-
return Status::NotImplemented("Keys of type ", *key);
381+
return Status::NotImplemented("Keys of type ", *key_type);
381382
}
382383

383384
return impl;

0 commit comments

Comments
 (0)