| 1233 | } |
| 1234 | |
| 1235 | ResultType Object::SetCapacity(ResultToken &aResultToken, int aID, int aFlags, ExprTokenType *aParam[], int aParamCount) |
| 1236 | { |
| 1237 | if (!ParamIndexIsNumeric(0)) |
| 1238 | return aResultToken.ParamError(1, aParam[0], _T("Number")); // Param index differs because this is actually the global function ObjSetCapacity(). |
| 1239 | |
| 1240 | index_t desired_count = (index_t)ParamIndexToInt64(0); |
| 1241 | if (desired_count < mFields.Length()) |
| 1242 | { |
| 1243 | // It doesn't seem intuitive to allow SetCapacity to truncate the fields array, so just reallocate |
| 1244 | // as necessary to remove any unused space. Allow negative values since SetCapacity(-1) seems more |
| 1245 | // intuitive than SetCapacity(0) when the contents aren't being discarded. |
| 1246 | desired_count = mFields.Length(); |
| 1247 | } |
| 1248 | if (desired_count == 0) |
| 1249 | { |
| 1250 | mFields.Free(); |
| 1251 | ASSERT(desired_count == mFields.Capacity()); |
| 1252 | } |
| 1253 | if (desired_count == mFields.Capacity() || SetInternalCapacity(desired_count)) |
| 1254 | { |
| 1255 | _o_return(mFields.Capacity()); |
| 1256 | } |
| 1257 | // At this point, failure isn't critical since nothing is being stored yet. However, it might be easier to |
| 1258 | // debug if an error is thrown here rather than possibly later, when the array attempts to resize itself to |
| 1259 | // fit new items. This also avoids the need for scripts to check if the return value is less than expected: |
| 1260 | _o_throw_oom; |
| 1261 | } |
| 1262 | |
| 1263 | ResultType Map::Capacity(ResultToken &aResultToken, int aID, int aFlags, ExprTokenType *aParam[], int aParamCount) |
| 1264 | { |
no test coverage detected