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