about summary refs log tree commit diff
path: root/src/rt/rust_obstack.cpp
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-12-25 19:18:02 -0800
committerBrian Anderson <banderson@mozilla.com>2011-12-25 19:18:05 -0800
commitb9b9b3e5705bc6cad760538441a5b3654dd55e58 (patch)
tree8aa23fef86e7ebf10daaabcacf60e3f50879e02b /src/rt/rust_obstack.cpp
parentb3eb9a003165e800d2c48083d794cb9879f3be89 (diff)
downloadrust-b9b9b3e5705bc6cad760538441a5b3654dd55e58.tar.gz
rust-b9b9b3e5705bc6cad760538441a5b3654dd55e58.zip
rt: Set the initial obstack size to 128 bytes
Double the size on each allocation
Diffstat (limited to 'src/rt/rust_obstack.cpp')
-rw-r--r--src/rt/rust_obstack.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/rt/rust_obstack.cpp b/src/rt/rust_obstack.cpp
index e8dbffd74a2..554043cf4f1 100644
--- a/src/rt/rust_obstack.cpp
+++ b/src/rt/rust_obstack.cpp
@@ -20,8 +20,8 @@
 #undef DPRINT
 #define DPRINT(fmt, ...)
 
-//const size_t DEFAULT_CHUNK_SIZE = 4096;
-const size_t DEFAULT_CHUNK_SIZE = 500000;
+const size_t DEFAULT_CHUNK_SIZE = 128;
+const size_t MAX_CHUNK_SIZE = (1024*64);
 const size_t DEFAULT_ALIGNMENT = 16;
 
 // A single type-tagged allocation in a chunk.
@@ -42,7 +42,6 @@ rust_obstack_chunk::alloc(size_t len, type_desc *tydesc) {
 
     if (sizeof(rust_obstack_alloc) + len > size - alen) {
         DPRINT("Not enough space, len=%lu!\n", len);
-        assert(0);      // FIXME
         return NULL;    // Not enough space.
     }
 
@@ -70,9 +69,15 @@ rust_obstack_chunk::mark() {
 // Allocates the given number of bytes in a new chunk.
 void *
 rust_obstack::alloc_new(size_t len, type_desc *tydesc) {
+    size_t default_chunk_size = DEFAULT_CHUNK_SIZE;
+    if (chunk) {
+	default_chunk_size = std::min(chunk->size * 2, MAX_CHUNK_SIZE);
+    }
+
     size_t chunk_size = std::max(sizeof(rust_obstack_alloc) + len,
-                                 DEFAULT_CHUNK_SIZE);
-    void *ptr = task->malloc(sizeof(chunk) + chunk_size, "obstack");
+                                 default_chunk_size);
+    void *ptr = task->malloc(sizeof(rust_obstack_chunk) + chunk_size,
+			     "obstack");
     DPRINT("making new chunk at %p, len %lu\n", ptr, chunk_size);
     chunk = new(ptr) rust_obstack_chunk(chunk, chunk_size);
     return chunk->alloc(len, tydesc);