aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--e-util/ChangeLog8
-rw-r--r--e-util/e-memory.c18
2 files changed, 17 insertions, 9 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index d370ef880e..36102ffee2 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,11 @@
+2000-11-22 Not Zed <NotZed@HelixCode.com>
+
+ * e-memory.c (e_mempool_alloc): If we dont get a big enough chunk
+ in the first node, give up. Otherwise we spend too much time
+ searching.
+ (e_mempool_strdup): Doh, and allocate enough for the terminating
+ NUL at that.
+
2000-11-21 Not Zed <NotZed@HelixCode.com>
* e-memory.c (e_memchunk_alloc0): New function to allocate a
diff --git a/e-util/e-memory.c b/e-util/e-memory.c
index 37ec181ce9..38bfefae8a 100644
--- a/e-util/e-memory.c
+++ b/e-util/e-memory.c
@@ -397,7 +397,7 @@ MemPool *e_mempool_new(int blocksize, int threshold, EMemPoolFlags flags)
* be rounded up to the mempool's alignment restrictions
* before being used.
**/
-void *e_mempool_alloc(MemPool *pool, int size)
+void *e_mempool_alloc(MemPool *pool, register int size)
{
size = (size + pool->align) & (~(pool->align));
if (size>=pool->threshold) {
@@ -408,17 +408,17 @@ void *e_mempool_alloc(MemPool *pool, int size)
pool->threshold_blocks = n;
return &n->data[0];
} else {
- MemPoolNode *n;
+ register MemPoolNode *n;
n = pool->blocks;
- while (n) {
- if (n->free >= size) {
- n->free -= size;
- return &n->data[n->free];
- }
- n = n->next;
+ if (n && n->free >= size) {
+ n->free -= size;
+ return &n->data[n->free];
}
+ /* maybe we could do some sort of the free blocks based on size, but
+ it doubt its worth it at all */
+
n = g_malloc(sizeof(*n) - sizeof(char) + pool->blocksize);
n->next = pool->blocks;
pool->blocks = n;
@@ -431,7 +431,7 @@ char *e_mempool_strdup(EMemPool *pool, const char *str)
{
char *out;
- out = e_mempool_alloc(pool, strlen(str));
+ out = e_mempool_alloc(pool, strlen(str)+1);
strcpy(out, str);
return out;