The overhead of de duplication operation is too high in function PushToNativePointerList

Make sure there is no repetition where the interface is called

https://gitee.com/openharmony/ark_js_runtime/issues/I56ARS?from=project-issue

Signed-off-by: yingguofeng@huawei.com <yingguofeng@huawei.com>
Change-Id: Ib9b248beffe62be5c7826782a0f3ab639f7c3d30
This commit is contained in:
yingguofeng@huawei.com 2022-05-07 17:21:10 +08:00
parent e9f1f0be86
commit b967a1c7c5
2 changed files with 2 additions and 11 deletions

View File

@ -539,9 +539,6 @@ void EcmaVM::ProcessReferences(const WeakRootVisitor &v0)
void EcmaVM::PushToNativePointerList(JSNativePointer *array)
{
if (std::find(nativePointerList_.begin(), nativePointerList_.end(), array) != nativePointerList_.end()) {
return;
}
nativePointerList_.emplace_back(array);
}
@ -549,6 +546,8 @@ void EcmaVM::RemoveFromNativePointerList(JSNativePointer *array)
{
auto iter = std::find(nativePointerList_.begin(), nativePointerList_.end(), array);
if (iter != nativePointerList_.end()) {
JSNativePointer *object = *iter;
object->Destroy();
nativePointerList_.erase(iter);
}
}

View File

@ -40,8 +40,6 @@ void JSArrayBuffer::Attach(JSThread *thread, uint32_t arrayBufferByteLength, JST
ASSERT(arrayBufferData.IsNativePointer());
SetArrayBufferByteLength(arrayBufferByteLength);
SetArrayBufferData(thread, arrayBufferData);
EcmaVM *vm = thread->GetEcmaVM();
vm->PushToNativePointerList(JSNativePointer::Cast(arrayBufferData.GetHeapObject()));
}
void JSArrayBuffer::Detach(JSThread *thread)
@ -52,12 +50,6 @@ void JSArrayBuffer::Detach(JSThread *thread)
return;
}
EcmaVM *vm = thread->GetEcmaVM();
// remove vm's control over arrayBufferData.
JSNativePointer *jsNativePointer = JSNativePointer::Cast(arrayBufferData.GetHeapObject());
vm->RemoveFromNativePointerList(jsNativePointer);
jsNativePointer->Destroy();
SetArrayBufferData(thread, JSTaggedValue::Null());
SetArrayBufferByteLength(0);
}