Remove GrTDArray.

Two dynamic array classes is enough.

R=reed@google.com
Review URL: https://codereview.appspot.com/7069047

git-svn-id: http://skia.googlecode.com/svn/trunk@7053 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi
index 17708b1..3248f03 100644
--- a/gyp/gpu.gypi
+++ b/gyp/gpu.gypi
@@ -105,7 +105,6 @@
       '<(skia_src_path)/gpu/GrStencilBuffer.cpp',
       '<(skia_src_path)/gpu/GrStencilBuffer.h',
       '<(skia_src_path)/gpu/GrTBSearch.h',
-      '<(skia_src_path)/gpu/GrTDArray.h',
       '<(skia_src_path)/gpu/GrSWMaskHelper.cpp',
       '<(skia_src_path)/gpu/GrSWMaskHelper.h',
       '<(skia_src_path)/gpu/GrSoftwarePathRenderer.cpp',
diff --git a/include/core/SkTDArray.h b/include/core/SkTDArray.h
index 997a070..eaf25c6 100644
--- a/include/core/SkTDArray.h
+++ b/include/core/SkTDArray.h
@@ -302,6 +302,15 @@
         this->reset();
     }
 
+    void visitAll(void visitor(T&)) const {
+        T* stop = this->end();
+        for (T* curr = this->begin(); curr < stop; curr++) {
+            if (*curr) {
+                visitor(*curr);
+            }
+        }
+    }
+
 #ifdef SK_DEBUG
     void validate() const {
         SkASSERT((fReserve == 0 && fArray == NULL) ||
diff --git a/src/gpu/GrAtlas.h b/src/gpu/GrAtlas.h
index f0114e3..005598e 100644
--- a/src/gpu/GrAtlas.h
+++ b/src/gpu/GrAtlas.h
@@ -13,7 +13,6 @@
 
 #include "GrPoint.h"
 #include "GrTexture.h"
-#include "GrTDArray.h"
 
 class GrGpu;
 class GrRectanizer;
diff --git a/src/gpu/GrBufferAllocPool.h b/src/gpu/GrBufferAllocPool.h
index 7ed4b0c..654ba74 100644
--- a/src/gpu/GrBufferAllocPool.h
+++ b/src/gpu/GrBufferAllocPool.h
@@ -12,9 +12,9 @@
 #define GrBufferAllocPool_DEFINED
 
 #include "GrNoncopyable.h"
-#include "GrTDArray.h"
 
 #include "SkTArray.h"
+#include "SkTDArray.h"
 
 class GrGeometryBuffer;
 class GrGpu;
@@ -170,7 +170,7 @@
     GrGpu*                          fGpu;
     bool                            fGpuIsReffed;
     bool                            fFrequentResetHint;
-    GrTDArray<GrGeometryBuffer*>    fPreallocBuffers;
+    SkTDArray<GrGeometryBuffer*>    fPreallocBuffers;
     size_t                          fMinBlockSize;
     BufferType                      fBufferType;
 
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index b84b0f1..b8f43d8 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -23,8 +23,6 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 
-extern void gr_run_unittests();
-
 #define DEBUG_INVAL_BUFFER    0xdeadcafe
 #define DEBUG_INVAL_START_IDX -1
 
@@ -41,10 +39,6 @@
 
     fClipMaskManager.setGpu(this);
 
-#if GR_DEBUG
-    //gr_run_unittests();
-#endif
-
     fGeomPoolStateStack.push_back();
 #if GR_DEBUG
     GeometryPoolState& poolState = fGeomPoolStateStack.back();
diff --git a/src/gpu/GrRectanizer.h b/src/gpu/GrRectanizer.h
index d1f5033..0be8324 100644
--- a/src/gpu/GrRectanizer.h
+++ b/src/gpu/GrRectanizer.h
@@ -12,7 +12,6 @@
 #define GrRectanizer_DEFINED
 
 #include "GrRect.h"
-#include "GrTDArray.h"
 
 class GrRectanizerPurgeListener {
 public:
diff --git a/src/gpu/GrTDArray.h b/src/gpu/GrTDArray.h
deleted file mode 100644
index 33b7a63..0000000
--- a/src/gpu/GrTDArray.h
+++ /dev/null
@@ -1,216 +0,0 @@
-
-/*
- * Copyright 2010 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-
-#ifndef GrTDArray_DEFINED
-#define GrTDArray_DEFINED
-
-#include "GrTypes.h"
-#include "GrRefCnt.h"
-
-static inline int GrInitialArrayAllocationCount() {
-    return 4;
-}
-
-static inline int GrNextArrayAllocationCount(int count) {
-    return count + ((count + 1) >> 1);
-}
-
-template <typename T> class GrTDArray {
-public:
-    GrTDArray() : fArray(NULL), fAllocated(0), fCount(0) {}
-    GrTDArray(const GrTDArray& src) {
-        fCount = fAllocated = src.fCount;
-        fArray = (T*)GrMalloc(fAllocated * sizeof(T));
-        memcpy(fArray, src.fArray, fCount * sizeof(T));
-    }
-    ~GrTDArray() {
-        if (fArray) {
-            GrFree(fArray);
-        }
-    }
-
-    bool isEmpty() const { return 0 == fCount; }
-    int count() const { return fCount; }
-
-    const T& at(int index) const {
-        GrAssert((unsigned)index < (unsigned)fCount);
-        return fArray[index];
-    }
-    T& at(int index) {
-        GrAssert((unsigned)index < (unsigned)fCount);
-        return fArray[index];
-    }
-
-    const T& operator[](int index) const { return this->at(index); }
-    T& operator[](int index) { return this->at(index); }
-
-    GrTDArray& operator=(const GrTDArray& src) {
-        if (fAllocated < src.fCount) {
-            fAllocated = src.fCount;
-            GrFree(fArray);
-            fArray = (T*)GrMalloc(fAllocated * sizeof(T));
-        }
-        fCount = src.fCount;
-        memcpy(fArray, src.fArray, fCount * sizeof(T));
-        return *this;
-    }
-
-    void reset() {
-        if (fArray) {
-            GrFree(fArray);
-            fArray = NULL;
-        }
-        fAllocated = fCount = 0;
-    }
-
-    T* begin() const { return fArray; }
-    T* end() const { return fArray + fCount; }
-    T* back() const { GrAssert(fCount); return fArray + (fCount - 1); }
-
-    T* prepend() {
-        this->growAt(0);
-        return fArray;
-    }
-
-    T* append() {
-        this->growAt(fCount);
-        return fArray + fCount - 1;
-    }
-
-    /**
-     *  index may be [0..count], so that you can insert at the end (like append)
-     */
-    T* insert(int index) {
-        GrAssert((unsigned)index <= (unsigned)fCount);
-        this->growAt(index);
-        return fArray + index;
-    }
-
-    void remove(int index) {
-        GrAssert((unsigned)index < (unsigned)fCount);
-        fCount -= 1;
-        if (index < fCount) {
-            int remaining = fCount - index;
-            memmove(fArray + index, fArray + index + 1, remaining * sizeof(T));
-        }
-    }
-
-    void removeShuffle(int index) {
-        GrAssert((unsigned)index < (unsigned)fCount);
-        fCount -= 1;
-        if (index < fCount) {
-            memmove(fArray + index, fArray + fCount, sizeof(T));
-        }
-    }
-
-    // Utility iterators
-
-    /**
-     *  Calls GrFree() on each element. Assumes each is NULL or was allocated
-     *  with GrMalloc().
-     */
-    void freeAll() {
-        T* stop = this->end();
-        for (T* curr = this->begin(); curr < stop; curr++) {
-            GrFree(*curr);
-        }
-        this->reset();
-    }
-
-    /**
-     *  Calls delete on each element. Assumes each is NULL or was allocated
-     *  with new.
-     */
-    void deleteAll() {
-        T* stop = this->end();
-        for (T* curr = this->begin(); curr < stop; curr++) {
-            delete *curr;
-        }
-        this->reset();
-    }
-
-    /**
-     *  Calls GrSafeUnref() on each element. Assumes each is NULL or is a
-     *  subclass of GrRefCnt.
-     */
-    void unrefAll() {
-        T* stop = this->end();
-        for (T* curr = this->begin(); curr < stop; curr++) {
-            GrSafeUnref(*curr);
-        }
-        this->reset();
-    }
-
-    void visit(void visitor(T&)) const {
-        T* stop = this->end();
-        for (T* curr = this->begin(); curr < stop; curr++) {
-            if (*curr) {
-                visitor(*curr);
-            }
-        }
-    }
-
-    int find(const T& elem) const {
-        int count = this->count();
-        T* curr = this->begin();
-        for (int i = 0; i < count; i++) {
-            if (elem == curr[i]) {
-                return i;
-            }
-        }
-        return -1;
-    }
-
-    friend bool operator==(const GrTDArray<T>& a, const GrTDArray<T>& b) {
-        return a.count() == b.count() &&
-               (0 == a.count() ||
-                0 == memcmp(a.begin(), b.begin(), a.count() * sizeof(T)));
-    }
-    friend bool operator!=(const GrTDArray<T>& a, const GrTDArray<T>& b) {
-        return !(a == b);
-    }
-
-private:
-    T*  fArray;
-    int fAllocated, fCount;
-
-    // growAt will increment fCount, reallocate fArray (as needed), and slide
-    // the contents of fArray to make a hole for new data at index.
-    void growAt(int index) {
-        GrAssert(fCount <= fAllocated);
-        if (0 == fAllocated) {
-            fAllocated = GrInitialArrayAllocationCount();
-            fArray = (T*)GrMalloc(fAllocated * sizeof(T));
-        } else if (fCount == fAllocated) {
-            fAllocated = GrNextArrayAllocationCount(fAllocated);
-            T* newArray = (T*)GrMalloc(fAllocated * sizeof(T));
-            memcpy(newArray, fArray, index * sizeof(T));
-            memcpy(newArray + index + 1, fArray + index,
-                   (fCount - index) * sizeof(T));
-            GrFree(fArray);
-            fArray = newArray;
-        } else {
-            // check that we're not just appending
-            if (index < fCount) {
-                memmove(fArray + index + 1, fArray + index,
-                        (fCount - index) * sizeof(T));
-            }
-        }
-        GrAssert(fCount < fAllocated);
-        fCount += 1;
-    }
-};
-
-extern void* GrTDArray_growAt(void*, int* allocated, int& count, int index,
-                              size_t);
-
-
-#endif
-
diff --git a/src/gpu/GrTHashCache.h b/src/gpu/GrTHashCache.h
index 8547237..c75a5a7 100644
--- a/src/gpu/GrTHashCache.h
+++ b/src/gpu/GrTHashCache.h
@@ -11,7 +11,8 @@
 #ifndef GrTHashCache_DEFINED
 #define GrTHashCache_DEFINED
 
-#include "GrTDArray.h"
+#include "GrTypes.h"
+#include "SkTDArray.h"
 
 // GrTDefaultFindFunctor implements the default find behavior for
 // GrTHashTable (i.e., return the first resource that matches the
@@ -58,7 +59,7 @@
 #endif
 
     // testing
-    const GrTDArray<T*>& getArray() const { return fSorted; }
+    const SkTDArray<T*>& getArray() const { return fSorted; }
 private:
     enum {
         kHashCount = 1 << kHashBits,
@@ -73,7 +74,7 @@
     }
 
     mutable T* fHash[kHashCount];
-    GrTDArray<T*> fSorted;
+    SkTDArray<T*> fSorted;
 
     // search fSorted, and return the found index, or ~index of where it
     // should be inserted
diff --git a/src/gpu/GrTextStrike.cpp b/src/gpu/GrTextStrike.cpp
index aebaaf8..4b55810 100644
--- a/src/gpu/GrTextStrike.cpp
+++ b/src/gpu/GrTextStrike.cpp
@@ -149,7 +149,7 @@
 GrTextStrike::~GrTextStrike() {
     GrAtlas::FreeLList(fAtlas);
     fFontScalerKey->unref();
-    fCache.getArray().visit(FreeGlyph);
+    fCache.getArray().visitAll(FreeGlyph);
 
 #if GR_DEBUG
     gCounter -= 1;
diff --git a/src/gpu/gl/GrGLCreateNullInterface.cpp b/src/gpu/gl/GrGLCreateNullInterface.cpp
index 6cca6c8..f450cc8 100644
--- a/src/gpu/gl/GrGLCreateNullInterface.cpp
+++ b/src/gpu/gl/GrGLCreateNullInterface.cpp
@@ -7,8 +7,8 @@
 
 
 #include "gl/GrGLInterface.h"
-#include "GrTDArray.h"
 #include "GrGLDefines.h"
+#include "SkTDArray.h"
 
 namespace { // added to suppress 'no previous prototype' warning
 
@@ -132,7 +132,7 @@
 
 // In debug builds we do asserts that ensure we agree with GL about when a buffer
 // is mapped.
-static GrTDArray<GrGLuint> gMappedBuffers;
+static SkTDArray<GrGLuint> gMappedBuffers;
 static GrGLuint gCurrArrayBuffer;
 static GrGLuint gCurrElementArrayBuffer;
 
diff --git a/src/gpu/gr_unittests.cpp b/src/gpu/gr_unittests.cpp
index 1d7653b..7a3a251 100644
--- a/src/gpu/gr_unittests.cpp
+++ b/src/gpu/gr_unittests.cpp
@@ -6,13 +6,10 @@
  * found in the LICENSE file.
  */
 
-
-
 #include "GrBinHashKey.h"
 #include "GrDrawTarget.h"
 #include "SkMatrix.h"
 #include "GrRedBlackTree.h"
-#include "GrTDArray.h"
 
 // FIXME: needs to be in a header
 void gr_run_unittests();
@@ -28,37 +25,6 @@
 }
 #include "GrTBSearch.h"
 
-static void dump(const GrTDArray<int>& array) {
-#if 0
-    for (int i = 0; i < array.count(); i++) {
-        printf(" %d", array[i]);
-    }
-    printf("\n");
-#endif
-}
-
-static void test_tdarray() {
-    GrTDArray<int> array;
-
-    *array.append() = 0; dump(array);
-    *array.append() = 2; dump(array);
-    *array.append() = 4; dump(array);
-    *array.append() = 6; dump(array);
-    GrAssert(array.count() == 4);
-
-    *array.insert(0) = -1; dump(array);
-    *array.insert(2) = 1; dump(array);
-    *array.insert(4) = 3; dump(array);
-    *array.insert(7) = 7; dump(array);
-    GrAssert(array.count() == 8);
-    array.remove(3); dump(array);
-    array.remove(0); dump(array);
-    array.removeShuffle(4); dump(array);
-    array.removeShuffle(1); dump(array);
-    GrAssert(array.count() == 4);
-}
-
-
 static void test_bsearch() {
     const int array[] = {
         1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99
@@ -106,7 +72,6 @@
 
 
 void gr_run_unittests() {
-    test_tdarray();
     test_bsearch();
     test_binHashKey();
     GrRedBlackTree<int>::UnitTest();