about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--alloc.c27
1 files changed, 6 insertions, 21 deletions
diff --git a/alloc.c b/alloc.c
index a51407f..bddad4d 100644
--- a/alloc.c
+++ b/alloc.c
@@ -92,15 +92,7 @@ struct mog_rbuf *mog_rbuf_new(size_t size)
 
         assert(size > 0 && "tried to allocate a zero-byte mog_rbuf");
 
-        /*
-         * only cache-align for common allocation sizes, for larger
-         * allocations it'll lead to fragmentation and we'll only
-         * end up touching later sections of memory...
-         */
-        if (size == MOG_RBUF_BASE_SIZE)
-                rbuf = mog_cachealign(bytes);
-        else
-                rbuf = xmalloc(bytes);
+        rbuf = mog_cachealign(bytes);
         rbuf->rcapa = size;
         /*
          * do not initialize rsize here, we only need rsize when we detach
@@ -146,7 +138,7 @@ struct mog_rbuf *mog_rbuf_detach(struct mog_rbuf *rbuf)
 }
 
 /*
- * Behaves similarly to realloc(), but is safe for posix_memalign()
+ * Behaves similarly to realloc(), but uses posix_memalign()
  * Returns a detached rbuf with the contents of +cur+
  * (which may be cur itself)
  * Releases memory and returns NULL if rbuf is too big.
@@ -166,17 +158,10 @@ struct mog_rbuf *mog_rbuf_grow(struct mog_rbuf *cur)
         if (new_size > MOG_RBUF_MAX_SIZE)
                 new_size = MOG_RBUF_MAX_SIZE;
         if (cur->rcapa < new_size) {
-                if (cur->rcapa == MOG_RBUF_BASE_SIZE) {
-                        /* can't safely realloc posix_memalign'ed memory */
-                        ret = mog_rbuf_new(new_size);
-                        memcpy(ret->rptr, cur->rptr, cur->rsize);
-                        if (cur != tls_rbuf)
-                                mog_rbuf_free(cur);
-                } else {
-                        assert(cur != tls_rbuf && "bug rbuf found in TLS");
-                        ret = xrealloc(cur, new_size + sizeof(struct mog_rbuf));
-                        ret->rcapa = new_size;
-                }
+                ret = mog_rbuf_new(new_size);
+                memcpy(ret->rptr, cur->rptr, cur->rsize);
+                if (cur != tls_rbuf)
+                        mog_rbuf_free(cur);
         } else {
                 /* this may not even happen, just in case: */
                 ret = mog_rbuf_detach(cur);