File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ namespace snmalloc
7171
7272 meta.debug_slab_invariant (is_short (), this );
7373
74- if (zero_mem == YesZero)
74+ if constexpr (zero_mem == YesZero)
7575 {
7676 if (rsize < PAGE_ALIGNED_SIZE )
7777 memory_provider.zero (p, rsize);
Original file line number Diff line number Diff line change @@ -80,12 +80,16 @@ extern "C"
8080 " Calling realloc on pointer that is not to the start of an allocation" );
8181 }
8282#endif
83+ size_t sz = Alloc::alloc_size (ptr);
84+ // Keep the current allocation if the given size is in the same sizeclass.
85+ if (sz == sizeclass_to_size (size_to_sizeclass (size)))
86+ return ptr;
87+
8388 void * p = SNMALLOC_NAME_MANGLE (malloc)(size);
84- if (p)
89+ if (p != nullptr )
8590 {
8691 assert (p == Alloc::external_pointer<Start>(p));
87- size_t sz =
88- (std::min)(size, SNMALLOC_NAME_MANGLE (malloc_usable_size)(ptr));
92+ sz = (std::min)(size, sz);
8993 memcpy (p, ptr, sz);
9094 SNMALLOC_NAME_MANGLE (free)(ptr);
9195 }
You can’t perform that action at this time.
0 commit comments