[JS IR] Optimize JS AST blocks memory consumption
This commit is contained in:
committed by
Space
parent
ea34e10b67
commit
c747d0e742
@@ -423,7 +423,7 @@ private val IrModuleFragment.jsModuleName: String
|
||||
get() = name.asString().dropWhile { it == '<' }.dropLastWhile { it == '>' }
|
||||
|
||||
private fun List<JsStatement>.toJsCodeString(): String =
|
||||
JsCompositeBlock().also { it.statements += this }.toString()
|
||||
JsCompositeBlock(this).toString()
|
||||
|
||||
enum class JsGenerationGranularity {
|
||||
WHOLE_PROGRAM,
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ class JsCallTransformer(private val jsOrJsFuncCall: IrCall, private val context:
|
||||
0 -> JsEmpty
|
||||
1 -> newStatements.single().withSource(jsOrJsFuncCall, context)
|
||||
// TODO: use transparent block (e.g. JsCompositeBlock)
|
||||
else -> JsCompositeBlock().apply { statements += newStatements }
|
||||
else -> JsCompositeBlock(newStatements)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.jetbrains.kotlin.js.util.AstUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import com.intellij.util.SmartList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -19,7 +18,7 @@ public class JsBlock extends SourceInfoAwareJsNode implements JsStatement {
|
||||
private final List<JsStatement> statements;
|
||||
|
||||
public JsBlock() {
|
||||
this(new ArrayList<JsStatement>());
|
||||
this(new SmartList<JsStatement>());
|
||||
}
|
||||
|
||||
public JsBlock(JsStatement statement) {
|
||||
|
||||
@@ -9,7 +9,11 @@ import org.jetbrains.kotlin.js.util.AstUtil;
|
||||
/**
|
||||
* Represents a JavaScript block which could not be rendered into a material one.
|
||||
*/
|
||||
class JsCompositeBlock(statements: List<JsStatement> = mutableListOf()) : JsBlock(statements) {
|
||||
class JsCompositeBlock : JsBlock {
|
||||
constructor() : super()
|
||||
constructor(statement: JsStatement) : super(statement)
|
||||
constructor(statements: List<JsStatement>) : super(statements)
|
||||
|
||||
override fun isTransparent(): Boolean {
|
||||
return true
|
||||
}
|
||||
@@ -20,4 +24,4 @@ class JsCompositeBlock(statements: List<JsStatement> = mutableListOf()) : JsBloc
|
||||
globalBlockCopy.statements.addAll(statementscopy);
|
||||
return globalBlockCopy.withMetadataFrom(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user