| 148 | |
| 149 | |
| 150 | void 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 |
| 205 | void ArrayBase::zero(Dynamic inFirst, Dynamic inCount) |
no test coverage detected