Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(957)

Unified Diff: include/private/SkTHash.h

Issue 2253993002: SkPDF: cache metrics once. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/pdf/SkPDFCanon.h » ('j') | src/pdf/SkPDFCanon.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « no previous file | src/pdf/SkPDFCanon.h » ('j') | src/pdf/SkPDFCanon.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698