mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 14:32:49 +00:00
Eliminate unused function maps
If a class contains more than 16 functions, the lookup works via a map rather than via a linear lookup in the functions array. If there are less than 16 functions, there is no need to allocate the map. This saves about 240 maps and 7600 map entries in the core libraries alone. BUG= R=asiva@google.com Review URL: https://codereview.chromium.org/1410443003 .
This commit is contained in:
parent
fbcccc25a5
commit
72328eaf93
|
@ -2168,8 +2168,8 @@ void Class::SetFunctions(const Array& value) const {
|
|||
ASSERT(!value.IsNull());
|
||||
StorePointer(&raw_ptr()->functions_, value.raw());
|
||||
const intptr_t len = value.Length();
|
||||
ClassFunctionsSet set(HashTables::New<ClassFunctionsSet>(len, Heap::kOld));
|
||||
if (len >= kFunctionLookupHashTreshold) {
|
||||
ClassFunctionsSet set(HashTables::New<ClassFunctionsSet>(len, Heap::kOld));
|
||||
Function& func = Function::Handle();
|
||||
for (intptr_t i = 0; i < len; ++i) {
|
||||
func ^= value.At(i);
|
||||
|
@ -2177,8 +2177,8 @@ void Class::SetFunctions(const Array& value) const {
|
|||
ASSERT(func.Owner() == raw());
|
||||
set.Insert(func);
|
||||
}
|
||||
}
|
||||
StorePointer(&raw_ptr()->functions_hash_table_, set.Release().raw());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -2204,6 +2204,7 @@ void Class::AddFunction(const Function& function) const {
|
|||
void Class::RemoveFunction(const Function& function) const {
|
||||
const Array& arr = Array::Handle(functions());
|
||||
StorePointer(&raw_ptr()->functions_, Object::empty_array().raw());
|
||||
StorePointer(&raw_ptr()->functions_hash_table_, Array::null());
|
||||
Function& entry = Function::Handle();
|
||||
for (intptr_t i = 0; i < arr.Length(); i++) {
|
||||
entry ^= arr.At(i);
|
||||
|
|
Loading…
Reference in a new issue