This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push:
new eaa8209ab5d branch-3.0: [fix](memory) Fix `PODArray::add_num_element`
#50756 (#50781)
eaa8209ab5d is described below
commit eaa8209ab5d4d61b2a7d6481dbcc7e6be6d54b0c
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon May 12 09:31:34 2025 +0800
branch-3.0: [fix](memory) Fix `PODArray::add_num_element` #50756 (#50781)
Cherry-picked from #50756
Co-authored-by: Xinyi Zou <[email protected]>
---
be/src/vec/common/pod_array.h | 6 +++---
be/test/vec/common/pod_array_test.cpp | 26 ++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/be/src/vec/common/pod_array.h b/be/src/vec/common/pod_array.h
index 9e09afd7144..2cfabaa5faf 100644
--- a/be/src/vec/common/pod_array.h
+++ b/be/src/vec/common/pod_array.h
@@ -414,12 +414,12 @@ public:
template <typename U, typename... TAllocatorParams>
void add_num_element(U&& x, uint32_t num, TAllocatorParams&&...
allocator_params) {
if (num != 0) {
- const auto new_end = this->c_end + this->byte_size(num);
- if (UNLIKELY(new_end > this->c_end_of_storage)) {
+ const auto growth_size = this->byte_size(num);
+ if (UNLIKELY(this->c_end + growth_size > this->c_end_of_storage)) {
this->reserve(this->size() + num);
}
std::fill(t_end(), t_end() + num, x);
- this->c_end = new_end;
+ this->c_end = this->c_end + growth_size;
}
}
diff --git a/be/test/vec/common/pod_array_test.cpp
b/be/test/vec/common/pod_array_test.cpp
index e8b0a67ffa0..db022a12729 100644
--- a/be/test/vec/common/pod_array_test.cpp
+++ b/be/test/vec/common/pod_array_test.cpp
@@ -498,6 +498,32 @@ TEST(PODArrayTest, PODArrayInsert) {
// }
// }
+TEST(PODArrayTest, PODArrayAddNumElement) {
+ static constexpr size_t initial_bytes = 32;
+ using Array = vectorized::PODArray<uint64_t, initial_bytes>;
+ size_t element_size = 8; // sizeof(uint64_t)
+ {
+ Array array;
+
+ array.add_num_element(1, 4);
+ ASSERT_EQ(array.size(), 4);
+ ASSERT_EQ(array.capacity(), 32 / element_size);
+ ASSERT_EQ(array, Array({1, 1, 1, 1}));
+
+ // call reserve
+ array.add_num_element(1, 2);
+ ASSERT_EQ(array.size(), 6);
+ ASSERT_EQ(array.capacity(), 64 / element_size);
+ ASSERT_EQ(array, Array({1, 1, 1, 1, 1, 1}));
+
+ // call reserve
+ array.add_num_element_without_reserve(1, 1);
+ ASSERT_EQ(array.size(), 7);
+ ASSERT_EQ(array.capacity(), 64 / element_size);
+ ASSERT_EQ(array, Array({1, 1, 1, 1, 1, 1, 1}));
+ }
+}
+
TEST(PODArrayTest, PODArrayAssign) {
{
vectorized::PaddedPODArray<uint64_t> array;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]