Skip to content

Commit 58ec873

Browse files
committed
try skipping memcpy and deallocation when old_capacity was zero
1 parent 9246886 commit 58ec873

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

inst/include/s2/util/gtl/compact_array.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,10 @@ class compact_array_base {
393393
value_allocator_type allocator;
394394

395395
T* new_ptr = allocator.allocate(capacity());
396-
memcpy(new_ptr, Array(), old_capacity * sizeof(T));
397-
allocator.deallocate(Array(), old_capacity);
396+
if (old_capacity > 0) {
397+
memcpy(new_ptr, Array(), old_capacity * sizeof(T));
398+
allocator.deallocate(Array(), old_capacity);
399+
}
398400

399401
SetArray(new_ptr);
400402
}

0 commit comments

Comments
 (0)