partially implement KT-2310 (only cache call result)
This commit is contained in:
@@ -53,8 +53,13 @@ public final class DynamicContext {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public TemporaryVariable declareTemporary(@NotNull JsExpression initExpression) {
|
public TemporaryVariable declareTemporary(@NotNull JsExpression initExpression) {
|
||||||
|
return declareTemporary(initExpression, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public TemporaryVariable declareTemporary(@NotNull JsExpression initExpression, boolean initialize) {
|
||||||
JsName temporaryName = currentScope.declareTemporary();
|
JsName temporaryName = currentScope.declareTemporary();
|
||||||
JsVars temporaryDeclaration = newVar(temporaryName, /*no init expression in var statement*/ null);
|
JsVars temporaryDeclaration = newVar(temporaryName, initialize ? initExpression : null);
|
||||||
addVarDeclaration(jsBlock(), temporaryDeclaration);
|
addVarDeclaration(jsBlock(), temporaryDeclaration);
|
||||||
return new TemporaryVariable(temporaryName, initExpression);
|
return new TemporaryVariable(temporaryName, initExpression);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,6 +157,11 @@ public final class TranslationContext {
|
|||||||
return dynamicContext.declareTemporary(initExpression);
|
return dynamicContext.declareTemporary(initExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public TemporaryVariable declareTemporary(@NotNull JsExpression initExpression, boolean initialize) {
|
||||||
|
return dynamicContext.declareTemporary(initExpression, initialize);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Namer namer() {
|
public Namer namer() {
|
||||||
return staticContext.getNamer();
|
return staticContext.getNamer();
|
||||||
|
|||||||
+5
-3
@@ -19,9 +19,11 @@ package org.jetbrains.k2js.translate.operation;
|
|||||||
import com.google.dart.compiler.backend.js.ast.JsBinaryOperation;
|
import com.google.dart.compiler.backend.js.ast.JsBinaryOperation;
|
||||||
import com.google.dart.compiler.backend.js.ast.JsConditional;
|
import com.google.dart.compiler.backend.js.ast.JsConditional;
|
||||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||||
|
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.psi.JetUnaryExpression;
|
import org.jetbrains.jet.lang.psi.JetUnaryExpression;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
import org.jetbrains.k2js.translate.context.TemporaryVariable;
|
||||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||||
import org.jetbrains.k2js.translate.reference.CallBuilder;
|
import org.jetbrains.k2js.translate.reference.CallBuilder;
|
||||||
import org.jetbrains.k2js.translate.reference.CallType;
|
import org.jetbrains.k2js.translate.reference.CallType;
|
||||||
@@ -62,9 +64,9 @@ public final class UnaryOperationTranslator {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static JsExpression translateExclExclOperator(@NotNull JetUnaryExpression expression, @NotNull TranslationContext context) {
|
private static JsExpression translateExclExclOperator(@NotNull JetUnaryExpression expression, @NotNull TranslationContext context) {
|
||||||
JsExpression translatedExpression = translateAsExpression(getBaseExpression(expression), context);
|
JsNameRef cachedValue = context.declareTemporary(translateAsExpression(getBaseExpression(expression), context), true).reference();
|
||||||
JsBinaryOperation notNullCheck = notNullCheck(context, translatedExpression);
|
JsBinaryOperation notNullCheck = notNullCheck(context, cachedValue);
|
||||||
return new JsConditional(notNullCheck, translatedExpression, context.namer().throwNPEFunctionCall());
|
return new JsConditional(notNullCheck, cachedValue, context.namer().throwNPEFunctionCall());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
Reference in New Issue
Block a user