mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
perf: prevent multiple case evaluations
This commit is contained in:
committed by
Jun Yang
parent
a9afc9730c
commit
807e840712
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user