| 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 |
no test coverage detected