Bug 1779940 part 2 - Add HashMap::put which relies on lookup. r=arai

The next patch is creating a cache which is capable of looking up different kind
of string types. However, each string type need some contextual information to
be able to compare them against each others, which adds complexity to the lookup
type. In addition, the keys are of only one string type, and therefore we try to
avoid storing this context as part of each key, but instead provide it with the
contextual information coming with the Lookup type.

Therefore, when we want to insert a key, which might already be present, using
`put`. We have to provide a `aLookup` argument which knows how to compare keys.

This also make the interface similar to `putNew` which already has the
distinctions between the `Lookup` argument and the `KeyInput` argument.

Differential Revision: https://phabricator.services.mozilla.com/D154512
This commit is contained in:
Nicolas B. Pierron 2022-08-25 15:03:29 +00:00
parent 13f4bc063d
commit 4d9b0fe251

View file

@ -248,7 +248,14 @@ class HashMap {
// false on OOM.
template <typename KeyInput, typename ValueInput>
[[nodiscard]] bool put(KeyInput&& aKey, ValueInput&& aValue) {
AddPtr p = lookupForAdd(aKey);
return put(aKey, std::forward<KeyInput>(aKey),
std::forward<ValueInput>(aValue));
}
template <typename KeyInput, typename ValueInput>
[[nodiscard]] bool put(const Lookup& aLookup, KeyInput&& aKey,
ValueInput&& aValue) {
AddPtr p = lookupForAdd(aLookup);
if (p) {
p->value() = std::forward<ValueInput>(aValue);
return true;