You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/05/23 23:27:28 UTC

[GitHub] [incubator-doris] xinyiZzz commented on a diff in pull request #9727: [opt] avoid memcpy when building page

xinyiZzz commented on code in PR #9727:
URL: https://github.com/apache/incubator-doris/pull/9727#discussion_r879936473


##########
be/src/util/faststring.cc:
##########
@@ -37,18 +37,20 @@ void faststring::GrowToAtLeast(size_t newcapacity) {
 
 void faststring::GrowArray(size_t newcapacity) {
     DCHECK_GE(newcapacity, capacity_);
-    std::unique_ptr<uint8_t[]> newdata(new uint8_t[newcapacity]);
-    if (len_ > 0) {
-        memcpy(&newdata[0], &data_[0], len_);
-    }
-    capacity_ = newcapacity;
+    uint8_t* newdata = NULL;
     if (data_ != initial_data_) {
-        delete[] data_;
+        newdata = (uint8_t*)realloc((void*)data_, newcapacity);
     } else {
+        newdata = (uint8_t*)malloc(newcapacity);
+        if (len_ > 0) {
+            memcpy(newdata, data_, len_);
+        }
+    }
+    capacity_ = newcapacity;
+    data_ = newdata;
+    if (data_ == initial_data_) {
         ASAN_POISON_MEMORY_REGION(initial_data_, arraysize(initial_data_));

Review Comment:
   initial_data_ is a reserved memory, which is no longer equal to after the first GrowArray.



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org