Skip to content

Commit 5380bf2

Browse files
panvaaduh95
authored andcommitted
src: avoid redundant DataPointer reallocations
Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #64552 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 29a938d commit 5380bf2

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

deps/ncrypto/ncrypto.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,12 @@ Buffer<void> DataPointer::release() {
501501
}
502502

503503
DataPointer DataPointer::resize(size_t len) {
504-
size_t actual_len = std::min(len_, len);
504+
const size_t actual_len = std::min(len_, len);
505+
if (actual_len == len_) return std::move(*this);
506+
505507
auto buf = release();
506-
if (actual_len == len_) return DataPointer(buf.data, actual_len);
508+
if (actual_len == 0) return DataPointer(buf.data, actual_len);
509+
507510
buf.data = OPENSSL_realloc(buf.data, actual_len);
508511
buf.len = actual_len;
509512
return DataPointer(buf);

0 commit comments

Comments
 (0)