test growing the array by a minimum amount (taken from nsVoidArray).
authordwitte@stanford.edu
Wed, 19 Dec 2007 01:56:28 -0800
changeset 9464 3286bd5dafa71337f3d54f8b5fa1baa233aad7e3
parent 9463 136589d145a698f382009d9ea1fd0ea20f80c4dd
child 9465 53b19cd504ea9fdb72656da64cd896bfc11fe61c
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherdermozilla-central@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone1.9b3pre
test growing the array by a minimum amount (taken from nsVoidArray).
xpcom/glue/nsTArray.cpp
--- a/xpcom/glue/nsTArray.cpp
+++ b/xpcom/glue/nsTArray.cpp
@@ -79,20 +79,25 @@ nsTArray_base::EnsureCapacity(size_type 
     header->mIsAutoArray = 0;
     mHdr = header;
     
     return PR_TRUE;
   }
 
   // Use doubling algorithm when forced to increase available capacity.
   NS_ASSERTION(mHdr->mCapacity > 0, "should not have buffer of zero size");
-  size_type temp = mHdr->mCapacity;
-  while (temp < capacity)
-    temp <<= 1;
-  capacity = temp;
+  if (capacity < 8) {
+    // grow to 8 elements
+    capacity = 8;
+  } else {
+    size_type temp = mHdr->mCapacity;
+    while (temp < capacity)
+      temp <<= 1;
+    capacity = temp;
+  }
 
   Header *header;
   if (UsesAutoArrayBuffer()) {
     // NS_Alloc and copy
     header = static_cast<Header*>
                         (malloc(sizeof(Header) + capacity * elemSize));
     if (!header)
       return PR_FALSE;