Allocate memory in SkTDynamicHash on first use.
This eliminates any dynamic allocation for hash tables that are never used.
This helps SkPicture, where some tables (SkPaint) are almost always used, but
some rarely (SkMatrix) or never (SkRegion).
This also removes the (as yet unimportant) ability for the hash table to
shrink. This makes resizing harder to reason about, so I'd like to leave it
out until we see a need.
BUG=skia:1850
R=tomhudson@chromium.org, reed@google.com
Author: mtklein@google.com
Review URL: https://codereview.chromium.org/136403004
git-svn-id: http://skia.googlecode.com/svn/trunk@13051 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/DynamicHashTest.cpp b/tests/DynamicHashTest.cpp
index 5e92ace..d881738 100644
--- a/tests/DynamicHashTest.cpp
+++ b/tests/DynamicHashTest.cpp
@@ -23,7 +23,6 @@
class Hash : public SkTDynamicHash<Entry, int, GetKey, GetHash, AreEqual> {
public:
Hash() : INHERITED() {}
- Hash(int capacity) : INHERITED(capacity) {}
// Promote protected methods to public for this test.
int capacity() const { return this->INHERITED::capacity(); }
@@ -44,8 +43,8 @@
Entry d = { 4, 5.0 };
Entry e = { 5, 6.0 };
- Hash hash(4);
- ASSERT(hash.capacity() == 4);
+ Hash hash;
+ ASSERT(hash.capacity() == 0);
hash.add(&a);
ASSERT(hash.capacity() == 4);
@@ -78,8 +77,7 @@
}
static void test_lookup(skiatest::Reporter* reporter) {
- Hash hash(4);
- ASSERT(hash.capacity() == 4);
+ Hash hash;
// These collide.
Entry a = { 1, 2.0 };
@@ -114,8 +112,7 @@
}
static void test_remove(skiatest::Reporter* reporter) {
- Hash hash(4);
- ASSERT(hash.capacity() == 4);
+ Hash hash;
// These collide.
Entry a = { 1, 2.0 };