deno.land / std@0.166.0 / node / internal / freelist.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.// Copyright Joyent and Node contributors. All rights reserved. MIT license.
type Fn<T> = (...args: unknown[]) => T;export class FreeList<T> { name: string; ctor: Fn<T>; max: number; list: Array<T>; constructor(name: string, max: number, ctor: Fn<T>) { this.name = name; this.ctor = ctor; this.max = max; this.list = []; }
alloc(): T { return this.list.length > 0 ? this.list.pop() : Reflect.apply(this.ctor, this, arguments); }
free(obj: T) { if (this.list.length < this.max) { this.list.push(obj); return true; } return false; }}
std

Version Info

Tagged at
a year ago