Skip to content
This repository was archived by the owner on Mar 6, 2019. It is now read-only.

Commit 69e768f

Browse files
author
tsauerwein
committed
Reduce number of arrays created
1 parent 5189956 commit 69e768f

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/ol/render/webgl/webglreplay.js

+19-11
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,18 @@ ol.render.webgl.ImageReplay = function(tolerance, maxExtent) {
199199
this.verticesBuffer_ = null;
200200

201201
/**
202-
* Start indices per feature.
203-
* @type {Array.<Array.<?>>}
202+
* Start index per feature (the index).
203+
* @type {Array.<number>}
204+
* @private
205+
*/
206+
this.startIndices_ = [];
207+
208+
/**
209+
* Start index per feature (the feature).
210+
* @type {Array.<ol.Feature>}
204211
* @private
205212
*/
206-
this.startIndexForFeature_ = [];
213+
this.startIndicesFeature_ = [];
207214

208215
/**
209216
* @type {number|undefined}
@@ -406,7 +413,8 @@ ol.render.webgl.ImageReplay.prototype.drawMultiLineStringGeometry =
406413
*/
407414
ol.render.webgl.ImageReplay.prototype.drawMultiPointGeometry =
408415
function(multiPointGeometry, feature) {
409-
this.startIndexForFeature_.push([this.indices_.length, feature]);
416+
this.startIndices_.push(this.indices_.length);
417+
this.startIndicesFeature_.push(feature);
410418
var flatCoordinates = multiPointGeometry.getFlatCoordinates();
411419
var stride = multiPointGeometry.getStride();
412420
this.drawCoordinates_(
@@ -426,7 +434,8 @@ ol.render.webgl.ImageReplay.prototype.drawMultiPolygonGeometry =
426434
*/
427435
ol.render.webgl.ImageReplay.prototype.drawPointGeometry =
428436
function(pointGeometry, feature) {
429-
this.startIndexForFeature_.push([this.indices_.length, feature]);
437+
this.startIndices_.push(this.indices_.length);
438+
this.startIndicesFeature_.push(feature);
430439
var flatCoordinates = pointGeometry.getFlatCoordinates();
431440
var stride = pointGeometry.getStride();
432441
this.drawCoordinates_(
@@ -723,26 +732,25 @@ ol.render.webgl.ImageReplay.prototype.drawHitDetectionReplay_ =
723732
goog.webgl.UNSIGNED_INT : goog.webgl.UNSIGNED_SHORT;
724733
var elementSize = context.hasOESElementIndexUint ? 4 : 2;
725734

726-
var i, groupStart, groupEnd, numItems, featureInfo, start, end;
727-
var featureIndex = this.startIndexForFeature_.length - 1;
735+
var i, groupStart, groupEnd, numItems, start, end;
736+
var featureIndex = this.startIndices_.length - 1;
728737
for (i = this.hitDetectionTextures_.length - 1; i >= 0; --i) {
729738
gl.bindTexture(goog.webgl.TEXTURE_2D, this.hitDetectionTextures_[i]);
730739
groupStart = (i > 0) ? this.hitDetectionGroupIndices_[i - 1] : 0;
731740
end = this.hitDetectionGroupIndices_[i];
732741

733742
// draw all features for this texture group
734743
while (featureIndex >= 0 &&
735-
this.startIndexForFeature_[featureIndex][0] >= groupStart) {
736-
featureInfo = this.startIndexForFeature_[featureIndex];
737-
start = featureInfo[0];
744+
this.startIndices_[featureIndex] >= groupStart) {
745+
start = this.startIndices_[featureIndex];
738746
numItems = end - start;
739747
var offsetInBytes = start * elementSize;
740748

741749
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
742750
gl.drawElements(
743751
goog.webgl.TRIANGLES, numItems, elementType, offsetInBytes);
744752

745-
var result = featureCallback(/** @type {ol.Feature} */ (featureInfo[1]));
753+
var result = featureCallback(this.startIndicesFeature_[featureIndex]);
746754
if (result) {
747755
return result;
748756
}

0 commit comments

Comments
 (0)