Bug 1084114 - Use a better buffer growth strategy during XDR encoding. r=luke.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 16 Oct 2014 19:03:19 -0700
changeset 210841 83544b7dad714d493bb3a044a50a170e055185e0
parent 210840 cbf06fe7f47a049662b813109522b64198da7362
child 210842 b83e5b5a80daa0cd8975475c2d2053644bc73cdb
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersluke
bugs1084114
milestone36.0a1
Bug 1084114 - Use a better buffer growth strategy during XDR encoding. r=luke.
js/src/vm/Xdr.cpp
--- a/js/src/vm/Xdr.cpp
+++ b/js/src/vm/Xdr.cpp
@@ -24,19 +24,21 @@ XDRBuffer::freeBuffer()
 #endif
 }
 
 bool
 XDRBuffer::grow(size_t n)
 {
     MOZ_ASSERT(n > size_t(limit - cursor));
 
-    const size_t MEM_BLOCK = 8192;
+    const size_t MIN_CAPACITY = 8192;
     size_t offset = cursor - base;
-    size_t newCapacity = JS_ROUNDUP(offset + n, MEM_BLOCK);
+    size_t newCapacity = mozilla::RoundUpPow2(offset + n);
+    if (newCapacity < MIN_CAPACITY)
+        newCapacity = MIN_CAPACITY;
     if (isUint32Overflow(newCapacity)) {
         js::gc::AutoSuppressGC suppressGC(cx());
         JS_ReportErrorNumber(cx(), js_GetErrorMessage, nullptr, JSMSG_TOO_BIG_TO_ENCODE);
         return false;
     }
 
     void *data = js_realloc(base, newCapacity);
     if (!data) {