MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / array_grow

Function array_grow

include/daScript/simulate/aot_builtin.h:218–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

216 void *builtin_das_aligned_alloc16(uint64_t size);
217
218 __forceinline void array_grow ( Context & context, Array & arr, uint32_t stride, LineInfo * at ) {
219 if ( arr.isLocked() ) context.throw_error_at(at, "can't resize locked array");
220 uint64_t newSize = arr.size + 1;
221 // Keep the int64 surface contract (long_length returns int64) — refuse to grow past INT64_MAX.
222 if ( newSize > uint64_t(INT64_MAX) ) {
223 context.throw_error_at(at, "array_grow: newSize exceeds INT64_MAX [newSize=%llu]", (unsigned long long)newSize);
224 }
225 if ( newSize > arr.capacity ) {
226 uint64_t newCapacity = uint64_t(1) << (64 - das_clz64(das::max(newSize, uint64_t(2)) - 1));
227 newCapacity = das::max(newCapacity, uint64_t(16));
228 // The pow2 round-up overflows past INT64_MAX when newSize > 2^62; clamp so the
229 // resulting capacity stays representable in the int64 long_capacity() surface.
230 if ( newCapacity > uint64_t(INT64_MAX) ) newCapacity = uint64_t(INT64_MAX);
231 array_reserve(context, arr, newCapacity, stride, at);
232 }
233 arr.size = newSize;
234 }
235
236 __forceinline int64_t builtin_array_push ( Array & pArray, int64_t index, int stride, Context * context, LineInfoArg * at ) {
237 uint64_t idx = pArray.size;

Callers 4

builtin_array_pushFunction · 0.85
builtin_array_push_zeroFunction · 0.85
builtin_array_push_backFunction · 0.85

Calls 4

das_clz64Function · 0.85
array_reserveFunction · 0.85
isLockedMethod · 0.80
throw_error_atMethod · 0.80

Tested by

no test coverage detected