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 210817 83544b7dad714d493bb3a044a50a170e055185e0
parent 210816 cbf06fe7f47a049662b813109522b64198da7362
child 210818 b83e5b5a80daa0cd8975475c2d2053644bc73cdb
push id50558
push usernnethercote@mozilla.com
push dateFri, 17 Oct 2014 02:22:04 +0000
treeherdermozilla-inbound@83544b7dad71 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1084114
milestone36.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 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) {