Skip to content

Commit 308a589

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 8125809 commit 308a589

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
@@ -282,9 +282,12 @@ Buffer<void> DataPointer::release() {
282282
}
283283

284284
DataPointer DataPointer::resize(size_t len) {
285-
size_t actual_len = std::min(len_, len);
285+
const size_t actual_len = std::min(len_, len);
286+
if (actual_len == len_) return std::move(*this);
287+
286288
auto buf = release();
287-
if (actual_len == len_) return DataPointer(buf.data, actual_len);
289+
if (actual_len == 0) return DataPointer(buf.data, actual_len);
290+
288291
buf.data = OPENSSL_realloc(buf.data, actual_len);
289292
buf.len = actual_len;
290293
return DataPointer(buf);

0 commit comments

Comments
 (0)