Merge pull request #428 from twpayne/gc-optimizations

GC optimizations
This commit is contained in:
Tom Payne
2013-03-25 03:54:15 -07:00
13 changed files with 128 additions and 124 deletions

View File

@@ -122,13 +122,13 @@ ol.source.DebugTileSource.prototype.expireCache = function(usedTiles) {
/**
* @inheritDoc
*/
ol.source.DebugTileSource.prototype.getTile = function(tileCoord) {
var key = tileCoord.toString();
if (this.tileCache_.containsKey(key)) {
return /** @type {!ol.DebugTile_} */ (this.tileCache_.get(key));
ol.source.DebugTileSource.prototype.getTile = function(z, x, y) {
var tileCoordKey = ol.TileCoord.getKeyZXY(z, x, y);
if (this.tileCache_.containsKey(tileCoordKey)) {
return /** @type {!ol.DebugTile_} */ (this.tileCache_.get(tileCoordKey));
} else {
var tile = new ol.DebugTile_(tileCoord, this.tileGrid);
this.tileCache_.set(key, tile);
var tile = new ol.DebugTile_(new ol.TileCoord(z, x, y), this.tileGrid);
this.tileCache_.set(tileCoordKey, tile);
return tile;
}
};

View File

@@ -7,6 +7,7 @@ goog.require('ol.ImageTile');
goog.require('ol.Projection');
goog.require('ol.Tile');
goog.require('ol.TileCache');
goog.require('ol.TileCoord');
goog.require('ol.TileState');
goog.require('ol.TileUrlFunction');
goog.require('ol.TileUrlFunctionType');
@@ -87,20 +88,21 @@ ol.source.ImageTileSource.prototype.expireCache = function(usedTiles) {
* @inheritDoc
*/
ol.source.ImageTileSource.prototype.getTile =
function(tileCoord, tileGrid, projection) {
var key = tileCoord.toString();
if (this.tileCache_.containsKey(key)) {
return /** @type {!ol.Tile} */ (this.tileCache_.get(key));
function(z, x, y, tileGrid, projection) {
var tileCoordKey = ol.TileCoord.getKeyZXY(z, x, y);
if (this.tileCache_.containsKey(tileCoordKey)) {
return /** @type {!ol.Tile} */ (this.tileCache_.get(tileCoordKey));
} else {
goog.asserts.assert(tileGrid);
goog.asserts.assert(projection);
var tileCoord = new ol.TileCoord(z, x, y);
var tileUrl = this.tileUrlFunction(tileCoord, tileGrid, projection);
var tile = new ol.ImageTile(
tileCoord,
goog.isDef(tileUrl) ? ol.TileState.IDLE : ol.TileState.EMPTY,
goog.isDef(tileUrl) ? tileUrl : '',
this.crossOrigin_);
this.tileCache_.set(key, tile);
this.tileCache_.set(tileCoordKey, tile);
return tile;
}
};
@@ -109,7 +111,8 @@ ol.source.ImageTileSource.prototype.getTile =
/**
* @inheritDoc
*/
ol.source.ImageTileSource.prototype.useTile = function(tileCoordKey) {
ol.source.ImageTileSource.prototype.useTile = function(z, x, y) {
var tileCoordKey = ol.TileCoord.getKeyZXY(z, x, y);
if (this.tileCache_.containsKey(tileCoordKey)) {
this.tileCache_.get(tileCoordKey);
}

View File

@@ -72,8 +72,8 @@ ol.source.TileSource.prototype.expireCache = goog.abstractMethod;
*
* @param {Object.<number, Object.<string, ol.Tile>>} loadedTilesByZ A lookup of
* loaded tiles by zoom level.
* @param {function(ol.TileCoord): ol.Tile} getTileIfLoaded A function that
* returns the tile only if it is fully loaded.
* @param {function(number, number, number): ol.Tile} getTileIfLoaded A function
* that returns the tile only if it is fully loaded.
* @param {number} z Zoom level.
* @param {ol.TileRange} tileRange Tile range.
* @return {boolean} The tile range is fully covered with loaded tiles.
@@ -82,15 +82,14 @@ ol.source.TileSource.prototype.findLoadedTiles = function(loadedTilesByZ,
getTileIfLoaded, z, tileRange) {
// FIXME this could be more efficient about filling partial holes
var fullyCovered = true;
var tile, tileCoord, tileCoordKey, x, y;
var tile, tileCoordKey, x, y;
for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
tileCoord = new ol.TileCoord(z, x, y);
tileCoordKey = tileCoord.toString();
tileCoordKey = ol.TileCoord.getKeyZXY(z, x, y);
if (loadedTilesByZ[z] && loadedTilesByZ[z][tileCoordKey]) {
continue;
}
tile = getTileIfLoaded(tileCoord);
tile = getTileIfLoaded(z, x, y);
if (!goog.isNull(tile)) {
if (!loadedTilesByZ[z]) {
loadedTilesByZ[z] = {};
@@ -122,7 +121,9 @@ ol.source.TileSource.prototype.getResolutions = function() {
/**
* @param {ol.TileCoord} tileCoord Tile coordinate.
* @param {number} z Tile coordinate z.
* @param {number} x Tile coordinate x.
* @param {number} y Tile coordinate y.
* @param {ol.tilegrid.TileGrid=} opt_tileGrid Tile grid.
* @param {ol.Projection=} opt_projection Projection.
* @return {!ol.Tile} Tile.
@@ -140,6 +141,8 @@ ol.source.TileSource.prototype.getTileGrid = function() {
/**
* Marks a tile coord as being used, without triggering a load.
* @param {string} tileCoordKey Tile coordinate key.
* @param {number} z Tile coordinate z.
* @param {number} x Tile coordinate x.
* @param {number} y Tile coordinate y.
*/
ol.source.TileSource.prototype.useTile = goog.nullFunction;