Use a switch statement, rather than ifs, in ol.render.canvas.Replay
This commit is contained in:
@@ -185,20 +185,24 @@ ol.render.canvas.Replay.prototype.replay_ =
|
|||||||
var instruction = instructions[i];
|
var instruction = instructions[i];
|
||||||
var type = /** @type {ol.render.canvas.Instruction} */ (instruction[0]);
|
var type = /** @type {ol.render.canvas.Instruction} */ (instruction[0]);
|
||||||
var geometry;
|
var geometry;
|
||||||
if (type == ol.render.canvas.Instruction.BEGIN_GEOMETRY) {
|
switch (type) {
|
||||||
|
case ol.render.canvas.Instruction.BEGIN_GEOMETRY:
|
||||||
geometry = /** @type {ol.geom.Geometry} */ (instruction[1]);
|
geometry = /** @type {ol.geom.Geometry} */ (instruction[1]);
|
||||||
if (renderGeometryFunction(geometry)) {
|
if (renderGeometryFunction(geometry)) {
|
||||||
++i;
|
++i;
|
||||||
} else {
|
} else {
|
||||||
i = /** @type {number} */ (instruction[2]);
|
i = /** @type {number} */ (instruction[2]);
|
||||||
}
|
}
|
||||||
} else if (type == ol.render.canvas.Instruction.BEGIN_PATH) {
|
break;
|
||||||
|
case ol.render.canvas.Instruction.BEGIN_PATH:
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
++i;
|
++i;
|
||||||
} else if (type == ol.render.canvas.Instruction.CLOSE_PATH) {
|
break;
|
||||||
|
case ol.render.canvas.Instruction.CLOSE_PATH:
|
||||||
context.closePath();
|
context.closePath();
|
||||||
++i;
|
++i;
|
||||||
} else if (type == ol.render.canvas.Instruction.DRAW_IMAGE) {
|
break;
|
||||||
|
case ol.render.canvas.Instruction.DRAW_IMAGE:
|
||||||
goog.asserts.assert(goog.isNumber(instruction[1]));
|
goog.asserts.assert(goog.isNumber(instruction[1]));
|
||||||
d = /** @type {number} */ (instruction[1]);
|
d = /** @type {number} */ (instruction[1]);
|
||||||
goog.asserts.assert(goog.isNumber(instruction[2]));
|
goog.asserts.assert(goog.isNumber(instruction[2]));
|
||||||
@@ -240,7 +244,8 @@ ol.render.canvas.Replay.prototype.replay_ =
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
} else if (type == ol.render.canvas.Instruction.END_GEOMETRY) {
|
break;
|
||||||
|
case ol.render.canvas.Instruction.END_GEOMETRY:
|
||||||
if (goog.isDef(geometryCallback)) {
|
if (goog.isDef(geometryCallback)) {
|
||||||
geometry = /** @type {ol.geom.Geometry} */ (instruction[1]);
|
geometry = /** @type {ol.geom.Geometry} */ (instruction[1]);
|
||||||
var data = /** @type {Object} */ (instruction[2]);
|
var data = /** @type {Object} */ (instruction[2]);
|
||||||
@@ -250,10 +255,12 @@ ol.render.canvas.Replay.prototype.replay_ =
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
} else if (type == ol.render.canvas.Instruction.FILL) {
|
break;
|
||||||
|
case ol.render.canvas.Instruction.FILL:
|
||||||
context.fill();
|
context.fill();
|
||||||
++i;
|
++i;
|
||||||
} else if (type == ol.render.canvas.Instruction.MOVE_TO_LINE_TO) {
|
break;
|
||||||
|
case ol.render.canvas.Instruction.MOVE_TO_LINE_TO:
|
||||||
goog.asserts.assert(goog.isNumber(instruction[1]));
|
goog.asserts.assert(goog.isNumber(instruction[1]));
|
||||||
d = /** @type {number} */ (instruction[1]);
|
d = /** @type {number} */ (instruction[1]);
|
||||||
goog.asserts.assert(goog.isNumber(instruction[2]));
|
goog.asserts.assert(goog.isNumber(instruction[2]));
|
||||||
@@ -263,11 +270,13 @@ ol.render.canvas.Replay.prototype.replay_ =
|
|||||||
context.lineTo(pixelCoordinates[d], pixelCoordinates[d + 1]);
|
context.lineTo(pixelCoordinates[d], pixelCoordinates[d + 1]);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
} else if (type == ol.render.canvas.Instruction.SET_FILL_STYLE) {
|
break;
|
||||||
|
case ol.render.canvas.Instruction.SET_FILL_STYLE:
|
||||||
goog.asserts.assert(goog.isString(instruction[1]));
|
goog.asserts.assert(goog.isString(instruction[1]));
|
||||||
context.fillStyle = /** @type {string} */ (instruction[1]);
|
context.fillStyle = /** @type {string} */ (instruction[1]);
|
||||||
++i;
|
++i;
|
||||||
} else if (type == ol.render.canvas.Instruction.SET_STROKE_STYLE) {
|
break;
|
||||||
|
case ol.render.canvas.Instruction.SET_STROKE_STYLE:
|
||||||
goog.asserts.assert(goog.isString(instruction[1]));
|
goog.asserts.assert(goog.isString(instruction[1]));
|
||||||
goog.asserts.assert(goog.isNumber(instruction[2]));
|
goog.asserts.assert(goog.isNumber(instruction[2]));
|
||||||
goog.asserts.assert(goog.isString(instruction[3]));
|
goog.asserts.assert(goog.isString(instruction[3]));
|
||||||
@@ -283,12 +292,15 @@ ol.render.canvas.Replay.prototype.replay_ =
|
|||||||
context.setLineDash(/** @type {Array.<number>} */ (instruction[6]));
|
context.setLineDash(/** @type {Array.<number>} */ (instruction[6]));
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
} else if (type == ol.render.canvas.Instruction.STROKE) {
|
break;
|
||||||
|
case ol.render.canvas.Instruction.STROKE:
|
||||||
context.stroke();
|
context.stroke();
|
||||||
++i;
|
++i;
|
||||||
} else {
|
break;
|
||||||
|
default:
|
||||||
goog.asserts.fail();
|
goog.asserts.fail();
|
||||||
++i; // consume the instruction anyway, to avoid an infinite loop
|
++i; // consume the instruction anyway, to avoid an infinite loop
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// assert that all instructions were consumed
|
// assert that all instructions were consumed
|
||||||
|
|||||||
Reference in New Issue
Block a user