( files: Files, bytecodeInfo: BytecodeCollectionResult | undefined, capacity: number )
| 111 | } |
| 112 | |
| 113 | function addBytecodeWithinCapacity( |
| 114 | files: Files, |
| 115 | bytecodeInfo: BytecodeCollectionResult | undefined, |
| 116 | capacity: number |
| 117 | ): number { |
| 118 | if (!bytecodeInfo || bytecodeInfo.totalSize <= 0 || capacity <= 0) { |
| 119 | return capacity; |
| 120 | } |
| 121 | |
| 122 | if (bytecodeInfo.totalSize <= capacity) { |
| 123 | addFiles(files, bytecodeInfo.files); |
| 124 | return capacity - bytecodeInfo.totalSize; |
| 125 | } |
| 126 | |
| 127 | const selected = lambdaKnapsack(bytecodeInfo.perItemSizes, capacity); |
| 128 | let remainingCapacity = capacity; |
| 129 | for (const p of selected) { |
| 130 | const file = bytecodeInfo.files[p]; |
| 131 | if (!file) continue; |
| 132 | files[p] = file; |
| 133 | remainingCapacity -= bytecodeInfo.perItemSizes.get(p) ?? 0; |
| 134 | } |
| 135 | |
| 136 | return remainingCapacity; |
| 137 | } |
| 138 | |
| 139 | async function addVendorBytecodeWithinCapacity({ |
| 140 | files, |
no test coverage detected