Replace unused entries with NaNs

This commit is contained in:
Tom Payne
2013-03-19 07:42:37 +01:00
parent 5169161d93
commit 713ad2cfb7
2 changed files with 34 additions and 9 deletions

View File

@@ -3,6 +3,12 @@ goog.provide('ol.structs.Buffer');
goog.require('ol.structs.IntegerSet');
/**
* @define {boolean} Replace unused entries with NaNs.
*/
ol.BUFFER_REPLACE_UNUSED_ENTRIES_WITH_NANS = goog.DEBUG;
/**
* @constructor
@@ -37,6 +43,14 @@ ol.structs.Buffer = function(opt_arr, opt_used, opt_dirty) {
if (opt_dirty && used !== 0) {
this.dirtySet_.addRange(0, used);
}
if (ol.BUFFER_REPLACE_UNUSED_ENTRIES_WITH_NANS) {
var arr = this.arr_;
var n = arr.length;
var i;
for (i = used; i < n; ++i) {
arr[i] = NaN;
}
}
};
@@ -111,6 +125,13 @@ ol.structs.Buffer.prototype.getFreeSet = function() {
ol.structs.Buffer.prototype.remove = function(index, size) {
this.freeSet_.addRange(index, index + size);
this.dirtySet_.removeRange(index, index + size);
if (ol.BUFFER_REPLACE_UNUSED_ENTRIES_WITH_NANS) {
var arr = this.arr_;
var i;
for (i = 0; i < size; ++i) {
arr[index + i] = NaN;
}
}
};