mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-02 17:19:38 +02:00
this fixes #391
This commit is contained in:
parent
6d7ad3a3c2
commit
e5d6acd712
@ -101,6 +101,14 @@ LogBuffer.prototype.dispose = function() {
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
LogBuffer.prototype.clearBuffer = function(beg, end) {
|
||||||
|
for ( var i = beg; i < end; i++ ) {
|
||||||
|
this.buffer[i] = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
LogBuffer.prototype.writeOne = function(args) {
|
LogBuffer.prototype.writeOne = function(args) {
|
||||||
// Reusing log entry = less memory churning
|
// Reusing log entry = less memory churning
|
||||||
var entry = this.buffer[this.writePtr];
|
var entry = this.buffer[this.writePtr];
|
||||||
@ -116,6 +124,13 @@ LogBuffer.prototype.writeOne = function(args) {
|
|||||||
// Grow the buffer between 1.5x-2x the current size
|
// Grow the buffer between 1.5x-2x the current size
|
||||||
if ( this.writePtr === this.readPtr ) {
|
if ( this.writePtr === this.readPtr ) {
|
||||||
var toMove = this.buffer.slice(0, this.writePtr);
|
var toMove = this.buffer.slice(0, this.writePtr);
|
||||||
|
// https://github.com/gorhill/uBlock/issues/391
|
||||||
|
// "The slice() method returns a shallow copy of a portion of an
|
||||||
|
// "array into a new array object."
|
||||||
|
// "shallow" => since we reuse entries, we need to remove the copied
|
||||||
|
// entries to prevent single instance of LogEntry being used in
|
||||||
|
// more than one slot.
|
||||||
|
this.clearBuffer(0, this.writePtr);
|
||||||
var minSize = Math.ceil(this.size * 1.5);
|
var minSize = Math.ceil(this.size * 1.5);
|
||||||
this.size += toMove.length;
|
this.size += toMove.length;
|
||||||
if ( this.size < minSize ) {
|
if ( this.size < minSize ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user