!8155 Compress singlecode for ldStringByIndex

Merge pull request !8155 from 刘智杰/intern_string
This commit is contained in:
openharmony_ci 2024-07-24 12:30:01 +00:00 committed by Gitee
commit b5a45212f5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 40 additions and 1 deletions

View File

@ -1190,7 +1190,9 @@ GateRef BuiltinsStringStubBuilder::CreateStringBySingleCharCode(GateRef glue, Ga
BRANCH(canStoreAsUtf8, &utf8, &utf16);
Bind(&utf8);
{
newBuilder.AllocLineStringObject(&result, &afterNew, Int32(1), true);
GateRef singleCharTable = GetSingleCharTable(glue);
result = GetValueFromTaggedArray(singleCharTable, charCode);
Jump(&exit);
}
Bind(&utf16);
{

View File

@ -38,3 +38,40 @@ function testHolyArray() {
print(arrayTest[9] === undefined);
}
testHolyArray();
function testStringIndex() {
class A {
constructor() {
var gotoFn = {
0: {}
};
this.gotoFn = gotoFn;
}
search(string) {
var state = 0;
var results = [];
for (var i=0; i<string.length; i++) {
var l = string[i];
if (!(l in this.gotoFn[state])) {
continue;
}
state = this.gotoFn[state][l];
}
return results;
};
}
let words = ""
for (let i = 0; i < 100; i++) {
words += "should find keyword" + i + " at position " + i + "and"
}
let ac = new A();
for (let i = 0; i < 100; i++) {
ac.search(words)
}
}
testStringIndex();