MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / fxSetIndexProperty

Function fxSetIndexProperty

xs/sources/xsProperty.c:335–419  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

333}
334
335txSlot* fxSetIndexProperty(txMachine* the, txSlot* instance, txSlot* array, txIndex index)
336{
337 txSlot* address = array->value.array.address;
338 txSlot* chunk = address;
339 txIndex length = array->value.array.length;
340 txIndex current;
341 txSize size;
342 txSlot* result;
343 txSlot* limit;
344 txIndex at;
345 if (address) {
346 current = (((txChunk*)(((txByte*)chunk) - sizeof(txChunk)))->size) / sizeof(txSlot);
347 if (length == current) {
348 if (index < length)
349 return address + index;
350 if (instance->flag & XS_DONT_PATCH_FLAG)
351 return C_NULL;
352 if (array->flag & XS_DONT_SET_FLAG)
353 return C_NULL;
354 current++;
355 size = fxMultiplyChunkSizes(the, current, sizeof(txSlot));
356 chunk = (txSlot*)fxRenewChunk(the, address, size);
357 if (!chunk) {
358 #ifndef mxNoArrayOverallocation
359 if (array->ID == XS_ARRAY_BEHAVIOR) {
360 txSize capacity = fxSizeToCapacity(the, size);
361 chunk = (txSlot*)fxNewGrowableChunk(the, size, capacity);
362 }
363 else
364 #endif
365 chunk = (txSlot*)fxNewChunk(the, size);
366 address = array->value.array.address;
367 c_memcpy(chunk, address, length * sizeof(txSlot));
368 }
369 result = chunk + length;
370 }
371 else {
372 result = address;
373 limit = result + current;
374 while (result < limit) {
375 at = *((txIndex*)result);
376 if (at == index)
377 return result;
378 if (at > index)
379 break;
380 result++;
381 }
382 if (instance->flag & XS_DONT_PATCH_FLAG)
383 return C_NULL;
384 if ((array->flag & XS_DONT_SET_FLAG) && (index >= length))
385 return C_NULL;
386 at = mxPtrDiff(result - address);
387 current++;
388 size = fxMultiplyChunkSizes(the, current, sizeof(txSlot));
389 chunk = (txSlot*)fxNewChunk(the, size);
390 address = array->value.array.address;
391 result = address + at;
392 limit = address + current - 1;

Callers 1

fxOrdinarySetPropertyFunction · 0.85

Calls 4

fxRenewChunkFunction · 0.85
fxSizeToCapacityFunction · 0.85
fxNewGrowableChunkFunction · 0.85
fxNewChunkFunction · 0.85

Tested by

no test coverage detected