MCPcopy
hub / github.com/webpack/webpack / allocate

Method allocate

lib/serialization/BinaryMiddleware.js:726–746  ·  view source on GitHub ↗
(bytesNeeded)

Source from the content-addressed store, hash-verified

724 * @param {number} bytesNeeded bytes needed
725 */
726 const allocate = (bytesNeeded) => {
727 if (currentBuffer !== null) {
728 if (currentBuffer.length - currentPosition >= bytesNeeded) return;
729 flush();
730 }
731 if (leftOverBuffer && leftOverBuffer.length >= bytesNeeded) {
732 currentBuffer = leftOverBuffer;
733 leftOverBuffer = null;
734 } else {
735 currentBuffer = Buffer.allocUnsafe(
736 Math.max(bytesNeeded, allocationScope.allocationSize)
737 );
738 if (
739 !(allocationScope.increaseCounter =
740 (allocationScope.increaseCounter + 1) % 4) &&
741 allocationScope.allocationSize < 16777216
742 ) {
743 allocationScope.allocationSize <<= 1;
744 }
745 }
746 };
747 const flush = () => {
748 if (currentBuffer !== null) {
749 if (currentPosition > 0) {

Callers

nothing calls this directly

Calls 1

flushFunction · 0.50

Tested by

no test coverage detected