MCPcopy Create free account
hub / github.com/HaxeFoundation/hxcpp / Realloc

Method Realloc

src/Array.cpp:150–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148
149
150void ArrayBase::Realloc(int inSize) const
151{
152 // Try to detect "push" case vs resizing to big array size explicitly by looking at gap
153 bool pushCase = (inSize<=mAlloc + 16);
154 if (!pushCase)
155 {
156 reserve(inSize);
157 }
158 else if (pushCase)
159 {
160 int newAlloc = inSize;
161 unsigned int elemSize = GetElementSize();
162 unsigned int minBytes = inSize*elemSize + 8;
163 unsigned int roundup = 64;
164 while(roundup<minBytes)
165 roundup<<=1;
166
167 if (roundup>64)
168 {
169 int half = 3*(roundup>>2);
170 if (minBytes<half)
171 roundup = half;
172 }
173 unsigned int bytes = roundup-8;
174
175 if (mBase)
176 {
177 bool wasUnamanaged = mAlloc<0;
178 if (wasUnamanaged)
179 {
180 char *base=(char *)hx::InternalNew(bytes,false);
181 memcpy(base,mBase,length*elemSize);
182 mBase = base;
183 }
184 else
185 {
186 mBase = (char *)hx::InternalRealloc(length*elemSize,mBase, bytes, true);
187 int o = bytes;
188 bytes = hx::ObjectSizeSafe(mBase);
189 }
190 }
191 else
192 {
193 mBase = (char *)hx::InternalNew(bytes,false);
194 #ifdef HXCPP_TELEMETRY
195 __hxt_new_array(mBase, bytes);
196 #endif
197 }
198
199 mAlloc = bytes/elemSize;
200 HX_OBJ_WB_GET(const_cast<ArrayBase *>(this),mBase);
201 }
202}
203
204// Set numeric values to 0, pointers to null, bools to false
205void ArrayBase::zero(Dynamic inFirst, Dynamic inCount)

Callers 3

SLJIT_CALL array_expandFunction · 0.80
array_expandMethod · 0.80

Calls 7

reserveFunction · 0.85
InternalNewFunction · 0.85
memcpyFunction · 0.85
InternalReallocFunction · 0.85
ObjectSizeSafeFunction · 0.85
GetElementSizeFunction · 0.50
__hxt_new_arrayFunction · 0.50

Tested by

no test coverage detected