Skip to content

Commit

Permalink
Allocate entire buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsaka committed Aug 9, 2024
1 parent 63d9ad2 commit 2047cca
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion velox/functions/prestosql/types/IPAddressType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class IPAddressCastOperator : public exec::CastOperator {
const auto* ipaddresses = input.as<SimpleVector<int128_t>>();
folly::ByteArray16 addrBytes;

flatResult->resize(rows.size());
flatResult->getRawStringBufferWithSpace(rows.size() * kIPAddressMaxStrLen);

context.applyToSelectedNoThrow(rows, [&](auto row) {
const auto intAddr = ipaddresses->valueAt(row);
memcpy(&addrBytes, &intAddr, kIPAddressBytes);
Expand All @@ -104,7 +107,6 @@ class IPAddressCastOperator : public exec::CastOperator {
folly::IPAddressV6 v6Addr(addrBytes);

exec::StringWriter<false> result(flatResult, row);
result.reserve(kIPAddressMaxStrLen);
if (v6Addr.isIPv4Mapped()) {
result.append(v6Addr.createIPv4().str());
} else {
Expand Down Expand Up @@ -155,6 +157,9 @@ class IPAddressCastOperator : public exec::CastOperator {
auto* flatResult = result.as<FlatVector<StringView>>();
const auto* ipaddresses = input.as<SimpleVector<int128_t>>();

flatResult->resize(rows.size());
flatResult->getRawStringBufferWithSpace(rows.size() * kIPAddressBytes);

context.applyToSelectedNoThrow(rows, [&](auto row) {
const auto intAddr = ipaddresses->valueAt(row);
folly::ByteArray16 addrBytes;
Expand Down

0 comments on commit 2047cca

Please sign in to comment.