mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-22 09:12:13 -05:00
HashTable: Correctly pass args to set
Problem: - Using regular functions rather than function templates results in the arguments not being deduced. This then requires the same function to be written multiple times and for `move` to be used rather than `forward`. Solution: - Collapse multiple function overloads to a single function template with a deduced argument. This allows the argument to be a forwarding reference and bind to either an l-value or r-value and forward the value.
This commit is contained in:
parent
2490fc79ad
commit
537bedbf38
Notes:
sideshowbarker
2024-07-18 22:42:21 +09:00
Author: https://github.com/ldm5180 Commit: https://github.com/SerenityOS/serenity/commit/537bedbf388 Pull-request: https://github.com/SerenityOS/serenity/pull/5193
1 changed files with 4 additions and 8 deletions
|
@ -203,15 +203,16 @@ public:
|
|||
*this = HashTable();
|
||||
}
|
||||
|
||||
HashSetResult set(T&& value)
|
||||
template<typename U = T>
|
||||
HashSetResult set(U&& value)
|
||||
{
|
||||
auto& bucket = lookup_for_writing(value);
|
||||
if (bucket.used) {
|
||||
(*bucket.slot()) = move(value);
|
||||
(*bucket.slot()) = forward<U>(value);
|
||||
return HashSetResult::ReplacedExistingEntry;
|
||||
}
|
||||
|
||||
new (bucket.slot()) T(move(value));
|
||||
new (bucket.slot()) T(forward<U>(value));
|
||||
bucket.used = true;
|
||||
if (bucket.deleted) {
|
||||
bucket.deleted = false;
|
||||
|
@ -221,11 +222,6 @@ public:
|
|||
return HashSetResult::InsertedNewEntry;
|
||||
}
|
||||
|
||||
HashSetResult set(const T& value)
|
||||
{
|
||||
return set(T(value));
|
||||
}
|
||||
|
||||
template<typename Finder>
|
||||
Iterator find(unsigned hash, Finder finder)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue