Reduce garbage generation
This commit is contained in:
@@ -97,6 +97,12 @@ class CanvasBuilder extends VectorContext {
|
|||||||
*/
|
*/
|
||||||
this.coordinates = [];
|
this.coordinates = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {import("../../coordinate.js").Coordinate}
|
||||||
|
*/
|
||||||
|
this.tmpCoordinate_ = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @protected
|
* @protected
|
||||||
* @type {Array<*>}
|
* @type {Array<*>}
|
||||||
@@ -140,8 +146,9 @@ class CanvasBuilder extends VectorContext {
|
|||||||
if (skipFirst) {
|
if (skipFirst) {
|
||||||
offset += stride;
|
offset += stride;
|
||||||
}
|
}
|
||||||
const lastCoord = [flatCoordinates[offset], flatCoordinates[offset + 1]];
|
let lastXCoord = flatCoordinates[offset];
|
||||||
const nextCoord = [NaN, NaN];
|
let lastYCoord = flatCoordinates[offset + 1];
|
||||||
|
const nextCoord = this.tmpCoordinate_;
|
||||||
let skipped = true;
|
let skipped = true;
|
||||||
|
|
||||||
let i, lastRel, nextRel;
|
let i, lastRel, nextRel;
|
||||||
@@ -151,8 +158,8 @@ class CanvasBuilder extends VectorContext {
|
|||||||
nextRel = coordinateRelationship(extent, nextCoord);
|
nextRel = coordinateRelationship(extent, nextCoord);
|
||||||
if (nextRel !== lastRel) {
|
if (nextRel !== lastRel) {
|
||||||
if (skipped) {
|
if (skipped) {
|
||||||
this.coordinates[myEnd++] = lastCoord[0];
|
this.coordinates[myEnd++] = lastXCoord;
|
||||||
this.coordinates[myEnd++] = lastCoord[1];
|
this.coordinates[myEnd++] = lastYCoord;
|
||||||
}
|
}
|
||||||
this.coordinates[myEnd++] = nextCoord[0];
|
this.coordinates[myEnd++] = nextCoord[0];
|
||||||
this.coordinates[myEnd++] = nextCoord[1];
|
this.coordinates[myEnd++] = nextCoord[1];
|
||||||
@@ -164,15 +171,15 @@ class CanvasBuilder extends VectorContext {
|
|||||||
} else {
|
} else {
|
||||||
skipped = true;
|
skipped = true;
|
||||||
}
|
}
|
||||||
lastCoord[0] = nextCoord[0];
|
lastXCoord = nextCoord[0];
|
||||||
lastCoord[1] = nextCoord[1];
|
lastYCoord = nextCoord[1];
|
||||||
lastRel = nextRel;
|
lastRel = nextRel;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Last coordinate equals first or only one point to append:
|
// Last coordinate equals first or only one point to append:
|
||||||
if ((closed && skipped) || i === offset + stride) {
|
if ((closed && skipped) || i === offset + stride) {
|
||||||
this.coordinates[myEnd++] = lastCoord[0];
|
this.coordinates[myEnd++] = lastXCoord;
|
||||||
this.coordinates[myEnd++] = lastCoord[1];
|
this.coordinates[myEnd++] = lastYCoord;
|
||||||
}
|
}
|
||||||
return myEnd;
|
return myEnd;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user