MCPcopy
hub / github.com/sparkjsdev/spark / alloc

Method alloc

src/utils.ts:360–380  ·  view source on GitHub ↗
(args: Args)

Source from the content-addressed store, hash-verified

358 // Allocate a new item from the free list, first checking if a existing item
359 // on the freelist is valid for the given args.
360 alloc(args: Args): T {
361 while (true) {
362 const item = this.items.pop();
363 if (!item) {
364 // No items in the free list, allocate a new one
365 break;
366 }
367 if (this.valid(item, args)) {
368 // Found a valid item, return it
369 // console.log(`FreeList.alloc(${JSON.stringify(args)}): found valid item. Reusing...`);
370 return item;
371 }
372 // Item isn't valid for our args, dispose of it and try again
373 if (this.dispose) {
374 // console.log(`FreeList.alloc(${JSON.stringify(args)}): disposing invalid item.`);
375 this.dispose(item);
376 }
377 }
378 // console.log(`FreeList.alloc(${JSON.stringify(args)}): allocating new item`);
379 return this.allocate(args);
380 }
381
382 free(item: T) {
383 // Return item to the free list

Callers 1

sortUpdateMethod · 0.80

Calls 2

validMethod · 0.80
disposeMethod · 0.65

Tested by

no test coverage detected