SteNicholas commented on code in PR #514:
URL: https://github.com/apache/paimon-cpp/pull/514#discussion_r4476256134
##########
src/paimon/common/memory/memory_slice.cpp:
##########
@@ -78,7 +78,9 @@ std::string_view MemorySlice::ReadStringView() const {
std::shared_ptr<Bytes> MemorySlice::CopyBytes(MemoryPool* pool) const {
auto bytes = std::make_shared<Bytes>(length_, pool);
- std::memcpy(const_cast<char*>(bytes->data()), Data(), length_);
+ if (length_ > 0) {
+ std::memcpy(const_cast<char*>(bytes->data()), Data(), length_);
Review Comment:
Bytes::data() const already returns char*, so const_cast<char*> is redundant
here. Please pass bytes->data() directly. The same cleanup applies to
copy->data() in the modified MemorySegment::GetOrCreateHeapMemory() call. This
makes the destination's mutability clear without suggesting that the copy
requires removing constness.
##########
src/paimon/common/memory/memory_segment_test.cpp:
##########
@@ -675,6 +675,20 @@ TEST(MemorySegmentTest, TestEqual) {
ASSERT_FALSE(seg2 == seg1);
}
+TEST(MemorySegmentTest, TestGetOrCreateHeapMemoryForEmptySegment) {
+ auto pool = paimon::GetDefaultPool();
+ auto view = MemorySegment::WrapView("", 0);
+ auto heap = view.GetOrCreateHeapMemory(pool.get());
+ ASSERT_TRUE(heap);
+ ASSERT_EQ(0u, heap->size());
+
+ auto owning = MemorySegment::Wrap(heap);
+ ASSERT_EQ(heap, owning.GetOrCreateHeapMemory(pool.get()));
+
+ auto null_view = MemorySegment::WrapView(nullptr, 0);
+ ASSERT_EQ(nullptr, null_view.GetOrCreateHeapMemory(pool.get()));
Review Comment:
Could the public GetOrCreateHeapMemory() method document the empty-segment
cases captured by this test? An owning empty segment returns its existing Bytes
object, WrapView("", 0) produces a non-null empty Bytes object, and
WrapView(nullptr, 0) returns nullptr. Callers need that distinction to know
whether they can dereference the result. A short Doxygen return-value
description in memory_segment.h would make this contract explicit.
--
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]