Comparing version 0.0.6 to 0.0.7
@@ -15,2 +15,4 @@ (function( global ) { | ||
this.size = this.start = 0; | ||
// set to callback fn if data is about to be overwritten | ||
this.overflow = false; | ||
// build CBuffer based on passed arguments | ||
@@ -50,5 +52,12 @@ if ( arguments.length > 1 || typeof arguments[0] !== 'number' ) { | ||
var i = 0; | ||
// check if overflow is set, and if data is about to be overwritten | ||
if ( this.overflow && this.size + arguments.length > this.length ) { | ||
// call overflow function and send data that's about to be overwritten | ||
for ( ; i < this.size + arguments.length - this.length; i++ ) { | ||
this.overflow( this.data[( this.end + i + 1 ) % this.length ], this ); | ||
} | ||
} | ||
// push items to the end, wrapping and erasing existing items | ||
// using arguments variable directly to reduce gc footprint | ||
for ( ; i < arguments.length; i++ ) { | ||
for ( i = 0; i < arguments.length; i++ ) { | ||
this.data[( this.end + i + 1 ) % this.length ] = arguments[i]; | ||
@@ -105,3 +114,10 @@ } | ||
var i = 0; | ||
for ( ; i < arguments.length; i++ ) { | ||
// check if overflow is set, and if data is about to be overwritten | ||
if ( this.overflow && this.size + arguments.length > this.length ) { | ||
// call overflow function and send data that's about to be overwritten | ||
for ( ; i < this.size + arguments.length - this.length; i++ ) { | ||
this.overflow( this.data[ this.end - ( i % this.length )], this ); | ||
} | ||
} | ||
for ( i = 0; i < arguments.length; i++ ) { | ||
this.data[( this.length + this.start - ( i % this.length ) - 1 ) % this.length ] = arguments[i]; | ||
@@ -204,2 +220,11 @@ } | ||
return this.data[( this.start + idx ) % this.length ] = arg; | ||
}, | ||
// return clean array of values | ||
toArray : function() { | ||
var narr = new Array( this.size ), | ||
i = 0; | ||
for ( ; i < this.size; i++ ) { | ||
narr[i] = this.data[( this.start + i ) % this.length ]; | ||
} | ||
return narr; | ||
} | ||
@@ -206,0 +231,0 @@ }; |
{ | ||
"name" : "CBuffer", | ||
"version" : "0.0.6", | ||
"version" : "0.0.7", | ||
"description" : "Circular Buffer JavaScript implementation", | ||
@@ -5,0 +5,0 @@ "homepage" : "http://github.com/trevnorris/cbuffer", |
@@ -45,1 +45,3 @@ ## JavaScript [Circular Buffer](http://en.wikipedia.org/wiki/Circular_buffer) Utility | ||
* set() | ||
* toArray() - Return clean ordered array of buffer | ||
* overflow - Set to function and will be called when data is about to be overwritten |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
13524
405
47
0