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

Function fxRenewChunk

xs/sources/xsMemory.c:1759–1812  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1757}
1758
1759void* fxRenewChunk(txMachine* the, void* theData, txSize size)
1760{
1761#if mxNoChunks
1762 txByte* aData = ((txByte*)theData) - sizeof(txChunk);
1763 txChunk* aChunk = (txChunk*)aData;
1764 size = fxAdjustChunkSize(the, size);
1765 if (size <= aChunk->size) {
1766 aChunk->size = size;
1767 return theData;
1768 }
1769 return C_NULL;
1770#else
1771 txByte* aData = ((txByte*)theData) - sizeof(txChunk);
1772 txChunk* aChunk = (txChunk*)aData;
1773 txSize capacity = (txSize)(aChunk->temporary - aData);
1774 txBlock* aBlock = the->firstBlock;
1775 size = fxAdjustChunkSize(the, size);
1776 if (size <= capacity) {
1777 the->currentChunksSize += size - aChunk->size;
1778 if (the->peakChunksSize < the->currentChunksSize)
1779 the->peakChunksSize = the->currentChunksSize;
1780 aChunk->size = size;
1781 #ifdef mxMetering
1782 the->meterIndex += size * XS_CHUNK_ALLOCATION_METERING;
1783 #endif
1784 return theData;
1785 }
1786 while (aBlock) {
1787 if (aChunk->temporary == aBlock->current) {
1788 txSize delta = size - capacity;
1789 if (aBlock->current + delta <= aBlock->limit) {
1790 the->currentChunksSize += size - aChunk->size;
1791 if (the->peakChunksSize < the->currentChunksSize)
1792 the->peakChunksSize = the->currentChunksSize;
1793 aBlock->current += delta;
1794 aChunk->temporary = aBlock->current;
1795 aChunk->size = size;
1796 #ifdef mxSnapshot
1797 c_memset(aData + capacity, 0, delta);
1798 #endif
1799 #ifdef mxMetering
1800 the->meterIndex += size * XS_CHUNK_ALLOCATION_METERING;
1801 #endif
1802 return theData;
1803 }
1804 else {
1805 return C_NULL;
1806 }
1807 }
1808 aBlock = aBlock->nextBlock;
1809 }
1810 return C_NULL;
1811#endif
1812}
1813
1814#if mxAliasInstance
1815void fxShare(txMachine* the)

Callers 15

fx_parseURLEncodeFunction · 0.85
fx_parseURLPercentEncodeFunction · 0.85
fx_parseURLPushPathFunction · 0.85
fx_parseURLSetPartFunction · 0.85
PiuTextBufferAppendFunction · 0.85
PiuTextBufferGrowFunction · 0.85
PiuContentUseIdleFunction · 0.85
PiuContent_set_nameAuxFunction · 0.85
fxSetIndexPropertyFunction · 0.85
fxSetIndexSizeFunction · 0.85
fxRunIDFunction · 0.85
fxSetArrayBufferLengthFunction · 0.85

Calls 1

fxAdjustChunkSizeFunction · 0.85

Tested by

no test coverage detected