perf: prevent multiple case evaluations

This commit is contained in:
Martin Schuster
2020-01-10 11:25:52 +08:00
committed by Jun Yang
parent a9afc9730c
commit 807e840712
+1 -1
View File
@@ -26,10 +26,10 @@ export default {
render: function * (ctx: Context, hash: Hash, emitter: Emitter) { render: function * (ctx: Context, hash: Hash, emitter: Emitter) {
const r = this.liquid.renderer const r = this.liquid.renderer
const cond = yield new Expression(this.cond).value(ctx)
for (let i = 0; i < this.cases.length; i++) { for (let i = 0; i < this.cases.length; i++) {
const branch = this.cases[i] const branch = this.cases[i]
const val = yield new Expression(branch.val).value(ctx) const val = yield new Expression(branch.val).value(ctx)
const cond = yield new Expression(this.cond).value(ctx)
if (val === cond) { if (val === cond) {
yield r.renderTemplates(branch.templates, ctx, emitter) yield r.renderTemplates(branch.templates, ctx, emitter)
return return