mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
AK: Return Optional<T&> from HashMap<..., T>::get()
This avoids a useless copy of the value, as most of the users (except one) actually just need a reference to the value.
This commit is contained in:
parent
1a74895680
commit
33e27c545e
Notes:
sideshowbarker
2024-07-17 22:09:47 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/33e27c545e Pull-request: https://github.com/SerenityOS/serenity/pull/13470 Reviewed-by: https://github.com/BenWiederhake ✅ Reviewed-by: https://github.com/creator1creeper1 Reviewed-by: https://github.com/sin-ack ✅
2 changed files with 4 additions and 4 deletions
|
@ -16,8 +16,8 @@ namespace AK {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct GenericTraits {
|
struct GenericTraits {
|
||||||
using PeekType = T;
|
using PeekType = T&;
|
||||||
using ConstPeekType = T;
|
using ConstPeekType = T const&;
|
||||||
static constexpr bool is_trivial() { return false; }
|
static constexpr bool is_trivial() { return false; }
|
||||||
static constexpr bool equals(const T& a, const T& b) { return a == b; }
|
static constexpr bool equals(const T& a, const T& b) { return a == b; }
|
||||||
template<Concepts::HashCompatible<T> U>
|
template<Concepts::HashCompatible<T> U>
|
||||||
|
|
|
@ -34,7 +34,7 @@ void WebAssemblyInstanceObject::initialize(JS::GlobalObject& global_object)
|
||||||
for (auto& export_ : instance.exports()) {
|
for (auto& export_ : instance.exports()) {
|
||||||
export_.value().visit(
|
export_.value().visit(
|
||||||
[&](Wasm::FunctionAddress const& address) {
|
[&](Wasm::FunctionAddress const& address) {
|
||||||
auto object = cache.function_instances.get(address);
|
Optional<JS::FunctionObject*> object = cache.function_instances.get(address);
|
||||||
if (!object.has_value()) {
|
if (!object.has_value()) {
|
||||||
object = create_native_function(global_object, address, export_.name());
|
object = create_native_function(global_object, address, export_.name());
|
||||||
cache.function_instances.set(address, *object);
|
cache.function_instances.set(address, *object);
|
||||||
|
@ -42,7 +42,7 @@ void WebAssemblyInstanceObject::initialize(JS::GlobalObject& global_object)
|
||||||
m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes);
|
m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes);
|
||||||
},
|
},
|
||||||
[&](Wasm::MemoryAddress const& address) {
|
[&](Wasm::MemoryAddress const& address) {
|
||||||
auto object = cache.memory_instances.get(address);
|
Optional<WebAssemblyMemoryObject*> object = cache.memory_instances.get(address);
|
||||||
if (!object.has_value()) {
|
if (!object.has_value()) {
|
||||||
object = heap().allocate<Web::Bindings::WebAssemblyMemoryObject>(global_object, global_object, address);
|
object = heap().allocate<Web::Bindings::WebAssemblyMemoryObject>(global_object, global_object, address);
|
||||||
cache.memory_instances.set(address, *object);
|
cache.memory_instances.set(address, *object);
|
||||||
|
|
Loading…
Reference in a new issue