mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
chore(ext/node): use array instead of Vec to avoid wrong capacity allocation (#25183)
This commit gets deno_node's customizer to use fixed-length array instead of `Vec` to avoid wrong capacity allocation. In the previous code we reserve a capacity of 14 for `external_references`. However, after pushing all the necessary `ExternalReference`s, it ends up with a length of 21, not 14. This means another allocation happens even though we reserve some space. To make sure that there will no longer be extra allocation, it should be a good idea to use fixed-length array here.
This commit is contained in:
parent
2ab4afc6b8
commit
b0ea6e0dc7
1 changed files with 107 additions and 106 deletions
131
ext/node/lib.rs
131
ext/node/lib.rs
|
@ -633,115 +633,116 @@ deno_core::extension!(deno_node,
|
|||
global_template_middleware = global_template_middleware,
|
||||
global_object_middleware = global_object_middleware,
|
||||
customizer = |ext: &mut deno_core::Extension| {
|
||||
let mut external_references = Vec::with_capacity(14);
|
||||
|
||||
let external_references = [
|
||||
vm::QUERY_MAP_FN.with(|query| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
named_query: *query,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
vm::GETTER_MAP_FN.with(|getter| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
named_getter: *getter,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
vm::SETTER_MAP_FN.with(|setter| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
named_setter: *setter,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
vm::DESCRIPTOR_MAP_FN.with(|descriptor| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
named_getter: *descriptor,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
vm::DELETER_MAP_FN.with(|deleter| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
named_deleter: *deleter,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
vm::ENUMERATOR_MAP_FN.with(|enumerator| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
enumerator: *enumerator,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
vm::DEFINER_MAP_FN.with(|definer| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
named_definer: *definer,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
|
||||
vm::INDEXED_QUERY_MAP_FN.with(|query| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
indexed_query: *query,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
vm::INDEXED_GETTER_MAP_FN.with(|getter| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
indexed_getter: *getter,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
vm::INDEXED_SETTER_MAP_FN.with(|setter| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
indexed_setter: *setter,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
vm::INDEXED_DESCRIPTOR_MAP_FN.with(|descriptor| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
indexed_getter: *descriptor,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
vm::INDEXED_DELETER_MAP_FN.with(|deleter| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
indexed_deleter: *deleter,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
vm::INDEXED_DEFINER_MAP_FN.with(|definer| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
indexed_definer: *definer,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
vm::INDEXED_ENUMERATOR_MAP_FN.with(|enumerator| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
enumerator: *enumerator,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
|
||||
global::GETTER_MAP_FN.with(|getter| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
named_getter: *getter,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
global::SETTER_MAP_FN.with(|setter| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
named_setter: *setter,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
global::QUERY_MAP_FN.with(|query| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
named_query: *query,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
global::DELETER_MAP_FN.with(|deleter| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
named_deleter: *deleter,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
global::ENUMERATOR_MAP_FN.with(|enumerator| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
enumerator: *enumerator,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
global::DEFINER_MAP_FN.with(|definer| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
named_definer: *definer,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
global::DESCRIPTOR_MAP_FN.with(|descriptor| {
|
||||
external_references.push(ExternalReference {
|
||||
ExternalReference {
|
||||
named_getter: *descriptor,
|
||||
});
|
||||
});
|
||||
}
|
||||
}),
|
||||
];
|
||||
|
||||
ext.external_references.to_mut().extend(external_references);
|
||||
},
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue