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

Function fxSetArrayLength

xs/sources/xsArray.c:717–755  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

715}
716
717txBoolean fxSetArrayLength(txMachine* the, txSlot* array, txIndex length)
718{
719 txSlot* address = array->value.array.address;
720 txSlot* chunk = address;
721 txBoolean success = 1;
722 if (address) {
723 txSize size = (((txChunk*)(((txByte*)chunk) - sizeof(txChunk)))->size) / sizeof(txSlot);
724 txSlot* result = address + size;
725 txSlot* limit = result;
726 txIndex at;
727 while (result > address) {
728 result--;
729 at = *((txIndex*)result);
730 if (length > at) {
731 result++;
732 break;
733 }
734 else if (result->flag & XS_DONT_DELETE_FLAG) {
735 result++;
736 length = at + 1;
737 success = 0;
738 break;
739 }
740 }
741 if (result < limit) {
742 if (result > address) {
743 size = mxPtrDiff(result - address);
744 chunk = (txSlot*)fxNewChunk(the, fxMultiplyChunkSizes(the, size, sizeof(txSlot)));
745 address = array->value.array.address;
746 c_memcpy(chunk, address, size * sizeof(txSlot));
747 }
748 else
749 chunk = C_NULL;
750 }
751 }
752 array->value.array.length = length;
753 array->value.array.address = chunk;
754 return success;
755}
756
757void fxSortArrayItems(txMachine* the, txSlot* function, txSlot* array, txNumber LENGTH, txSlot* target)
758{

Callers 3

fxArrayLengthSetterFunction · 0.85
fxArrayDefineOwnPropertyFunction · 0.85
fx_ArrayFunction · 0.85

Calls 1

fxNewChunkFunction · 0.85

Tested by

no test coverage detected