From 44b819a703c4602d133163c395f799ba8e5400f0 Mon Sep 17 00:00:00 2001 From: ctw-ian Date: Thu, 16 Feb 2023 12:01:58 +0800 Subject: [PATCH] Optimize abc size of ts2abc by removing useless string items Issue: Signed-off-by: ctw-ian Change-Id: I92c78a572f9203640ea43b27bfdd9ae5235208a7 --- ts2panda/src/ts2panda.ts | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/ts2panda/src/ts2panda.ts b/ts2panda/src/ts2panda.ts index f6d17a09f2e..5057c74af21 100644 --- a/ts2panda/src/ts2panda.ts +++ b/ts2panda/src/ts2panda.ts @@ -17,12 +17,17 @@ import * as ts from "typescript"; import { CmdOptions } from "./cmdOptions"; import { SourceTextModuleRecord } from "./ecmaModule"; import { + Createarraywithbuffer, + Createobjectwithbuffer, + Defineclasswithbuffer, Imm, IRNode, IRNodeKind, Label, + Newlexenvwithname, OperandType, - VReg + VReg, + WideNewlexenvwithname, } from "./irnodes"; import { LOGD } from "./log"; import { PandaGen } from "./pandagen"; @@ -134,8 +139,10 @@ export class Ts2Panda { let imm = operand; insImms.push(imm.value); } else if (typeof (operand) === "string") { - insIds.push(operand); - Ts2Panda.strings.add(operand); + if (!this.escapeLitIdString(insn, operand)) { + insIds.push(operand); + Ts2Panda.strings.add(operand); + } } else if (operand instanceof Label) { let labelName = Ts2Panda.labelPrefix + operand.id; insIds.push(labelName); @@ -162,6 +169,23 @@ export class Ts2Panda { }; } + static escapeLitIdString(insn: IRNode, operand: string): boolean { + if (insn instanceof Createarraywithbuffer || insn instanceof Createobjectwithbuffer || + insn instanceof Newlexenvwithname || insn instanceof WideNewlexenvwithname) { + return true; + } + + if (!(insn instanceof Defineclasswithbuffer)) { + return false; + } + + if (insn.operands[2] == operand) { + return true; + } + + return false; + } + static dumpStringsArray(ts2abc: any) { let strings_arr = Array.from(Ts2Panda.strings); -- Gitee