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

Function array_resize

src/simulate/runtime_array.cpp:90–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88 }
89
90 void array_resize ( Context & context, Array & arr, uint64_t newSize, uint32_t stride, bool zero, LineInfo * at ) {
91 if ( arr.isLocked() ) context.throw_error_at(at, "can't resize locked array");
92 // The daslang surface contract is `long_length(arr) : int64`, so a size that doesn't
93 // fit in int64_t would wrap negative on the way out. Enforce the cap up front so the
94 // int64 API stays well-defined.
95 if ( newSize > uint64_t(INT64_MAX) ) {
96 context.throw_error_at(at, "array_resize: newSize exceeds INT64_MAX [newSize=%llu]", (unsigned long long)newSize);
97 }
98 if ( newSize > arr.capacity ) {
99 uint64_t newCapacity = uint64_t(1) << (64 - das_clz64(das::max(newSize, uint64_t(2)) - 1));
100 newCapacity = das::max(newCapacity, uint64_t(16));
101 // The pow2 round-up overflows past INT64_MAX when newSize > 2^62; clamp so the
102 // resulting capacity stays representable in the int64 long_capacity() surface.
103 if ( newCapacity > uint64_t(INT64_MAX) ) newCapacity = uint64_t(INT64_MAX);
104 array_reserve(context, arr, newCapacity, stride, at);
105 }
106 if ( zero && newSize>arr.size ) {
107 memset ( arr.data + arr.size*stride, 0, size_t(newSize-arr.size)*size_t(stride) );
108 }
109 arr.size = newSize;
110 }
111
112 // GoodArrayIterator
113

Callers 13

live_load_bytesFunction · 0.85
beforeArrayMethod · 0.85
scanArrayMethod · 0.85
das_array_resizeFunction · 0.85
das_array_resize_i64Function · 0.85
builtin_array_resizeFunction · 0.85
builtin_array_resize_i64Function · 0.85
builtin_array_eraseFunction · 0.85
builtin_array_erase_i64Function · 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