!9842 optimize CopyArray

Merge pull request !9842 from wpy111/master
This commit is contained in:
openharmony_ci 2024-10-22 00:30:53 +00:00 committed by Gitee
commit d063257c08
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 52 additions and 9 deletions

View File

@ -3021,14 +3021,10 @@ JSHandle<TaggedArray> ObjectFactory::CopyArray(const JSHandle<TaggedArray> &old,
JSHandle<TaggedArray> newArray(thread_, header);
newArray->SetLength(newLength);
newArray->SetExtraLength(old->GetExtraLength());
for (uint32_t i = 0; i < newLength; i++) {
JSTaggedValue value = old->Get(i);
if (old->GetClass()->IsMutantTaggedArray()) {
newArray->Set<false>(thread_, i, value);
} else {
newArray->Set(thread_, i, value);
}
if (old->GetClass()->IsMutantTaggedArray()) {
newArray->Copy<false>(thread_, 0, 0, *old, newLength);
} else {
newArray->Copy(thread_, 0, 0, *old, newLength);
}
return newArray;

View File

@ -72,6 +72,7 @@ template <bool needBarrier>
inline void TaggedArray::Copy(const JSThread* thread, uint32_t dstStart, uint32_t srcStart,
const TaggedArray* srcArray, uint32_t count)
{
DISALLOW_GARBAGE_COLLECTION;
ASSERT((dstStart + count <= GetLength()) && "TaggedArray::Copy dst count is out of range");
ASSERT((srcStart + count <= srcArray->GetLength()) && "TaggedArray::Copy src count is out of range");
size_t taggedTypeSize = JSTaggedValue::TaggedTypeSize();

View File

@ -472,4 +472,50 @@ print(srcutf16.slice(0, 13)); // bytes > 16 && bytes % 16 > 8 && bytes % 8 > 0
print(srcutf16.slice(0, 16)); // bytes == 2 * 16
print(srcutf16.slice(0, 25)); // bytes > 16 && bytes % 16 != 0
print(srcutf16.slice(0, 28)); // bytes == 7 * 8
print(srcutf16.slice(0, 32)); // bytes == 4 * 16
print(srcutf16.slice(0, 32)); // bytes == 4 * 16
var str11;
var result11;
var re11 = /[Cz]/;
var re12 = /([Cz])/;
function createHaystack() {
let s = "abCdefgz";
for (let i = 0; i < 3; i++) s += s;
return s;
}
function SimpleSplit2() {
result11 = str11.split(re11);
if (result11.length != 17) {
print("fail!");
}
}
function Function1Replace(re) {
result11 = re[Symbol.replace](str11, String);
if (result11 != "abCdefgzabCdefgzabCdefgzabCdefgzabCdefgzabCdefgzabCdefgzabCdefgz") {
print("fail!");
}
}
str11 = createHaystack();
function SimpleMatch1() {
result11 = str11.match(re11);
if (result11[0] != 'C') {
print("fail!");
}
}
for (let i = 0; i < 10; i++) {
SimpleMatch1();
}
for (let i = 0; i < 10; i++) {
SimpleSplit2();
}
for (let i = 0; i < 100; i++) {
Function1Replace(re12);
}