| Index: include/private/SkTHash.h
|
| diff --git a/include/private/SkTHash.h b/include/private/SkTHash.h
|
| index 8a644e3b019750a768c806934f9635925b3e0f6b..1e8602543dd0e1a5ea6dcf081126992376269053 100644
|
| --- a/include/private/SkTHash.h
|
| +++ b/include/private/SkTHash.h
|
| @@ -48,15 +48,16 @@ public:
|
| // The pointers returned by set() and find() are valid only until the next call to set().
|
| // The pointers you receive in foreach() are only valid for its duration.
|
|
|
| - // Copy val into the hash table, returning a pointer to the copy now in the table.
|
| + // Move val into the hash table, returning a pointer to the copy now in the table.
|
| // If there already is an entry in the table with the same key, we overwrite it.
|
| - T* set(const T& val) {
|
| + T* set(T val) {
|
| if (4 * (fCount+fRemoved) >= 3 * fCapacity) {
|
| this->resize(fCapacity > 0 ? fCapacity * 2 : 4);
|
| }
|
| - return this->uncheckedSet(val);
|
| + return this->uncheckedSet(std::move(val));
|
| }
|
|
|
| +
|
| // If there is an entry in the table with this key, return a pointer to it. If not, NULL.
|
| T* find(const K& key) const {
|
| uint32_t hash = Hash(key);
|
| @@ -116,7 +117,7 @@ public:
|
| }
|
|
|
| private:
|
| - T* uncheckedSet(const T& val) {
|
| + T* uncheckedSet(T val) {
|
| const K& key = Traits::GetKey(val);
|
| uint32_t hash = Hash(key);
|
| int index = hash & (fCapacity-1);
|
| @@ -127,7 +128,7 @@ private:
|
| if (s.removed()) {
|
| fRemoved--;
|
| }
|
| - s.val = val;
|
| + s.val = std::move(val);
|
| s.hash = hash;
|
| fCount++;
|
| return &s.val;
|
| @@ -135,7 +136,7 @@ private:
|
| if (hash == s.hash && key == Traits::GetKey(s.val)) {
|
| // Overwrite previous entry.
|
| // Note: this triggers extra copies when adding the same value repeatedly.
|
| - s.val = val;
|
| + s.val = std::move(val);
|
| return &s.val;
|
| }
|
| index = this->next(index, n);
|
| @@ -156,7 +157,7 @@ private:
|
| for (int i = 0; i < oldCapacity; i++) {
|
| const Slot& s = oldSlots[i];
|
| if (!s.empty() && !s.removed()) {
|
| - this->uncheckedSet(s.val);
|
| + this->uncheckedSet(std::move(s.val));
|
| }
|
| }
|
| SkASSERT(fCount == oldCount);
|
| @@ -209,9 +210,8 @@ public:
|
|
|
| // Set key to val in the table, replacing any previous value with the same key.
|
| // We copy both key and val, and return a pointer to the value copy now in the table.
|
| - V* set(const K& key, const V& val) {
|
| - Pair in = { key, val };
|
| - Pair* out = fTable.set(in);
|
| + V* set(const K& key, V val) {
|
| + Pair* out = fTable.set(Pair{ key, std::move(val) });
|
| return &out->val;
|
| }
|
|
|
|
|