aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/HashTest.cpp
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2017-03-10 11:51:07 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-10 17:28:04 +0000
commit053730de732922ecee21be665af111ce671ce045 (patch)
treea888069700f090ebe9d2b210d53e54e5efcfa2d2 /tests/HashTest.cpp
parent566e53c7003920ff45c72498754060804b657c68 (diff)
Fix SkTHashTable dangling values
The element rearrange logic in SkTHashTable::remove() marks empty slots as such, but does not reset their value. When breaking out of the rearrange loop, we must also reset the last empty slot value to avoid retaining unwanted copies. Change-Id: I8ba2a25088c0aa5210277124e0917224cb295691 Reviewed-on: https://skia-review.googlesource.com/9533 Reviewed-by: Mike Klein <mtklein@chromium.org> Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'tests/HashTest.cpp')
-rw-r--r--tests/HashTest.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/HashTest.cpp b/tests/HashTest.cpp
index 4a884e3b5b..667f8ea4c0 100644
--- a/tests/HashTest.cpp
+++ b/tests/HashTest.cpp
@@ -6,6 +6,7 @@
*/
#include "SkChecksum.h"
+#include "SkRefCnt.h"
#include "SkString.h"
#include "SkTHash.h"
#include "Test.h"
@@ -65,6 +66,21 @@ DEF_TEST(HashMap, r) {
map.reset();
REPORTER_ASSERT(r, map.count() == 0);
+
+ {
+ // Test that we don't leave dangling values in empty slots.
+ SkTHashMap<int, sk_sp<SkRefCnt>> refMap;
+ auto ref = sk_make_sp<SkRefCnt>();
+ REPORTER_ASSERT(r, ref->unique());
+
+ refMap.set(0, ref);
+ REPORTER_ASSERT(r, refMap.count() == 1);
+ REPORTER_ASSERT(r, !ref->unique());
+
+ refMap.remove(0);
+ REPORTER_ASSERT(r, refMap.count() == 0);
+ REPORTER_ASSERT(r, ref->unique());
+ }
}
DEF_TEST(HashSet, r) {