22
33const {
44 Array,
5+ ArrayPrototypeFill
56} = primordials ;
67
78// Currently optimal queue size, tested on V8 6.0 - 6.6. Must be power of two.
@@ -17,18 +18,18 @@ const kMask = kSize - 1;
1718// +-----------+ <-----\ +-----------+ <------\ +-----------+
1819// | [null] | \----- | next | \------- | next |
1920// +-----------+ +-----------+ +-----------+
20- // | item | <-- bottom | item | <-- bottom | [empty] |
21- // | item | | item | | [empty] |
22- // | item | | item | | [empty] |
23- // | item | | item | | [empty] |
21+ // | item | <-- bottom | item | <-- bottom | undefined |
22+ // | item | | item | | undefined |
23+ // | item | | item | | undefined |
24+ // | item | | item | | undefined |
2425// | item | | item | bottom --> | item |
2526// | item | | item | | item |
2627// | ... | | ... | | ... |
2728// | item | | item | | item |
2829// | item | | item | | item |
29- // | [empty] | <-- top | item | | item |
30- // | [empty] | | item | | item |
31- // | [empty] | | [empty] | <-- top top --> | [empty] |
30+ // | undefined | <-- top | item | | item |
31+ // | undefined | | item | | item |
32+ // | undefined | | undefined | <-- top top --> | undefined |
3233// +-----------+ +-----------+ +-----------+
3334//
3435// Or, if there is only one circular buffer, it looks something
@@ -40,12 +41,12 @@ const kMask = kSize - 1;
4041// +-----------+ +-----------+
4142// | [null] | | [null] |
4243// +-----------+ +-----------+
43- // | [empty] | | item |
44- // | [empty] | | item |
45- // | item | <-- bottom top --> | [empty] |
46- // | item | | [empty] |
47- // | [empty] | <-- top bottom --> | item |
48- // | [empty] | | item |
44+ // | undefined | | item |
45+ // | undefined | | item |
46+ // | item | <-- bottom top --> | undefined |
47+ // | item | | undefined |
48+ // | undefined | <-- top bottom --> | item |
49+ // | undefined | | item |
4950// +-----------+ +-----------+
5051//
5152// Adding a value means moving `top` forward by one, removing means
@@ -60,7 +61,7 @@ class FixedCircularBuffer {
6061 constructor ( ) {
6162 this . bottom = 0 ;
6263 this . top = 0 ;
63- this . list = new Array ( kSize ) ;
64+ this . list = ArrayPrototypeFill ( new Array ( kSize ) , undefined ) ;
6465 this . next = null ;
6566 }
6667
0 commit comments