bkietz commented on a change in pull request #7410: URL: https://github.com/apache/arrow/pull/7410#discussion_r440202771
########## File path: cpp/src/arrow/compute/kernels/scalar_validity.cc ########## @@ -0,0 +1,97 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "arrow/compute/kernels/common.h" + +#include "arrow/util/bit_util.h" +#include "arrow/util/bitmap_ops.h" + +namespace arrow { +namespace compute { + +struct IsValid { + static void Call(KernelContext* ctx, const Scalar& in, Scalar* out) { + checked_cast<BooleanScalar*>(out)->value = in.is_valid; + } + + static void Call(KernelContext* ctx, const ArrayData& arr, ArrayData* out) { + if (arr.buffers[0] != nullptr && out->offset == arr.offset && + out->length == arr.length) { + out->buffers[1] = arr.buffers[0]; + return; + } Review comment: My thought was that this optimization won't be available frequently enough to sacrifice the benefits of preallocated memory when zero copy isn't possible The intent here was to allow immediate reclamation of memory when we can determine we don't need it. I'll refactor to assume zero copy is usually possible ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org