diff --git a/cpp/src/arrow/compute/row/grouper.cc b/cpp/src/arrow/compute/row/grouper.cc index d62333af3700..a342e5a6b1bf 100644 --- a/cpp/src/arrow/compute/row/grouper.cc +++ b/cpp/src/arrow/compute/row/grouper.cc @@ -341,43 +341,44 @@ struct GrouperImpl : public Grouper { impl->ctx_ = ctx; for (size_t i = 0; i < key_types.size(); ++i) { - // TODO(wesm): eliminate this probably unneeded shared_ptr copy - std::shared_ptr key = key_types[i].GetSharedPtr(); + const auto& key_type = key_types[i]; - if (key->id() == Type::BOOL) { + if (key_type.id() == Type::BOOL) { impl->encoders_[i] = std::make_unique(); continue; } - if (key->id() == Type::DICTIONARY) { - impl->encoders_[i] = - std::make_unique(key, ctx->memory_pool()); + if (key_type.id() == Type::DICTIONARY) { + impl->encoders_[i] = std::make_unique( + key_type.GetSharedPtr(), ctx->memory_pool()); continue; } - if (is_fixed_width(key->id())) { - impl->encoders_[i] = std::make_unique(key); + if (is_fixed_width(key_type.id())) { + impl->encoders_[i] = + std::make_unique(key_type.GetSharedPtr()); continue; } - if (is_binary_like(key->id())) { - impl->encoders_[i] = - std::make_unique>(key); + if (is_binary_like(key_type.id())) { + impl->encoders_[i] = std::make_unique>( + key_type.GetSharedPtr()); continue; } - if (is_large_binary_like(key->id())) { + if (is_large_binary_like(key_type.id())) { impl->encoders_[i] = - std::make_unique>(key); + std::make_unique>( + key_type.GetSharedPtr()); continue; } - if (key->id() == Type::NA) { + if (key_type.id() == Type::NA) { impl->encoders_[i] = std::make_unique(); continue; } - return Status::NotImplemented("Keys of type ", *key); + return Status::NotImplemented("Keys of type ", *key_type); } return impl;