Bug 1219238 - remove AutoArray from mozStorageSQLFunctions.cpp; r=mak
authorNathan Froyd <froydnj@mozilla.com>
Tue, 27 Oct 2015 21:22:52 -0400
changeset 270351 f623c844dca9a01dfa3f55791df285c4e16c3ef0
parent 270350 7ff25645a05855ef09a359b4d46d4701976003ff
child 270352 e22433400ec20695abb55e4912baf0dea7dc4413
push id29612
push userkwierso@gmail.com
push dateFri, 30 Oct 2015 23:36:00 +0000
treeherdermozilla-central@1596ab6985cb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1219238
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1219238 - remove AutoArray from mozStorageSQLFunctions.cpp; r=mak nsAutoTArray is practically the same thing; we should just use that and avoid code duplications.
storage/mozStorageSQLFunctions.cpp
--- a/storage/mozStorageSQLFunctions.cpp
+++ b/storage/mozStorageSQLFunctions.cpp
@@ -112,58 +112,16 @@ likeCompare(nsAString::const_iterator aP
 
     aPatternItr++;
   }
 
   return aStringItr == aStringEnd;
 }
 
 /**
- * This class manages a dynamic array.  It can represent an array of any 
- * reasonable size, but if the array is "N" elements or smaller, it will be
- * stored using fixed space inside the auto array itself.  If the auto array
- * is a local variable, this internal storage will be allocated cheaply on the
- * stack, similar to nsAutoString.  If a larger size is requested, the memory
- * will be dynamically allocated from the heap.  Since the destructor will
- * free any heap-allocated memory, client code doesn't need to care where the
- * memory came from.
- */
-template <class T, size_t N> class AutoArray
-{
-
-public:
-
-  explicit AutoArray(size_t size)
-  : mBuffer(size <= N ? mAutoBuffer : new T[size])
-  {
-  }
-
-  ~AutoArray()
-  { 
-    if (mBuffer != mAutoBuffer)
-      delete[] mBuffer; 
-  }
-
-  /**
-   * Return the pointer to the allocated array.
-   * @note If the array allocation failed, get() will return nullptr!
-   *
-   * @return the pointer to the allocated array
-   */
-  T *get() 
-  {
-    return mBuffer; 
-  }
-
-private:
-  T *mBuffer;           // Points to mAutoBuffer if we can use it, heap otherwise.
-  T mAutoBuffer[N];     // The internal memory buffer that we use if we can.
-};
-
-/**
  * Compute the Levenshtein Edit Distance between two strings.
  * 
  * @param aStringS
  *        a string
  * @param aStringT
  *        another string
  * @param _result
  *        an outparam that will receive the edit distance between the arguments
@@ -201,27 +159,23 @@ levenshteinDistance(const nsAString &aSt
     //
     // Note that the row width is sLen + 1 and the column height is tLen + 1,
     // where sLen is the length of the string "s" and tLen is the length of "t".
     // The first row and the first column are initialized as shown, and
     // the algorithm computes the remaining cells row-by-row, and
     // left-to-right within each row.  The computation only requires that
     // we be able to see the current row and the previous one.
 
-    // Allocate memory for two rows.  Use AutoArray's to manage the memory
-    // so we don't have to explicitly free it, and so we can avoid the expense
-    // of memory allocations for relatively small strings.
-    AutoArray<int, nsAutoString::kDefaultStorageSize> row1(sLen + 1);
-    AutoArray<int, nsAutoString::kDefaultStorageSize> row2(sLen + 1);
+    // Allocate memory for two rows.
+    nsAutoTArray<int, nsAutoString::kDefaultStorageSize> row1;
+    nsAutoTArray<int, nsAutoString::kDefaultStorageSize> row2;
 
     // Declare the raw pointers that will actually be used to access the memory.
-    int *prevRow = row1.get();
-    NS_ENSURE_TRUE(prevRow, SQLITE_NOMEM);
-    int *currRow = row2.get();
-    NS_ENSURE_TRUE(currRow, SQLITE_NOMEM);
+    int *prevRow = row1.AppendElements(sLen + 1);
+    int *currRow = row2.AppendElements(sLen + 1);
 
     // Initialize the first row.
     for (uint32_t i = 0; i <= sLen; i++)
         prevRow[i] = i;
 
     const char16_t *s = aStringS.BeginReading();
     const char16_t *t = aStringT.BeginReading();