FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
node/lib/freelist.js at https · reado/node · GitHub
reado
node
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
node
/
lib
/
freelist.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
22 lines (18 loc) · 622 Bytes
Breadcrumbs
node
/
lib
/
freelist.js
Copy path
File metadata and controls
22 lines (18 loc) · 622 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// This is a free list to avoid creating so many of the same object.
exports
.
FreeList
=
function
(
name
,
max
,
constructor
)
{
this
.
name
=
name
;
this
.
constructor
=
constructor
;
this
.
max
=
max
;
this
.
list
=
[
]
;
}
;
exports
.
FreeList
.
prototype
.
alloc
=
function
(
)
{
//debug("alloc " + this.name + " " + this.list.length);
return
this
.
list
.
length
?
this
.
list
.
shift
(
)
:
this
.
constructor
.
apply
(
this
,
arguments
)
;
}
;
exports
.
FreeList
.
prototype
.
free
=
function
(
obj
)
{
//debug("free " + this.name + " " + this.list.length);
if
(
this
.
list
.
length
<
this
.
max
)
{
this
.
list
.
push
(
obj
)
;
}
}
;
Back
|
FazBrowse Home
|
New Git URL