From 13229e0c91bf069be2b00fbf159921f8fef235b4 Mon Sep 17 00:00:00 2001 From: Lukas Taegert-Atkinson Date: Mon, 16 Dec 2019 06:24:28 +0100 Subject: [PATCH] Some mini-optimizations --- src/ast/nodes/IfStatement.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/ast/nodes/IfStatement.ts b/src/ast/nodes/IfStatement.ts index 892256c91f6..3fe33b457d4 100644 --- a/src/ast/nodes/IfStatement.ts +++ b/src/ast/nodes/IfStatement.ts @@ -45,13 +45,15 @@ export default class IfStatement extends StatementBase implements DeoptimizableE include(context: InclusionContext, includeChildrenRecursively: IncludeChildren) { this.included = true; - const testValue = this.getTestValue(); if (includeChildrenRecursively) { this.includeRecursively(includeChildrenRecursively, context); - } else if (testValue === UnknownValue) { - this.includeUnknownTest(context); } else { - this.includeKnownTest(context); + const testValue = this.getTestValue(); + if (testValue === UnknownValue) { + this.includeUnknownTest(context); + } else { + this.includeKnownTest(context, testValue); + } } } @@ -90,16 +92,19 @@ export default class IfStatement extends StatementBase implements DeoptimizableE private getTestValue(): LiteralValueOrUnknown { if (this.testValue === unset) { - this.testValue = this.test.getLiteralValueAtPath(EMPTY_PATH, SHARED_RECURSION_TRACKER, this); + return (this.testValue = this.test.getLiteralValueAtPath( + EMPTY_PATH, + SHARED_RECURSION_TRACKER, + this + )); } return this.testValue; } - private includeKnownTest(context: InclusionContext) { + private includeKnownTest(context: InclusionContext, testValue: LiteralValueOrUnknown) { if (this.test.shouldBeIncluded(context)) { this.test.include(context, false); } - const testValue = this.getTestValue(); if (testValue && this.consequent.shouldBeIncluded(context)) { this.consequent.include(context, false); }