diff options
author | Not Zed <NotZed@Ximian.com> | 2003-11-14 07:20:50 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2003-11-14 07:20:50 +0800 |
commit | b4d89f6bbcff72bdb3f4670be8f632bf8b1c2a3c (patch) | |
tree | 53cd73aebaa36c01a56aec803176647141126210 /camel/camel-mime-parser.c | |
parent | 2699c4c41f9bfe08f6b69c982a7014f577ee0786 (diff) | |
download | gsoc2013-evolution-b4d89f6bbcff72bdb3f4670be8f632bf8b1c2a3c.tar gsoc2013-evolution-b4d89f6bbcff72bdb3f4670be8f632bf8b1c2a3c.tar.gz gsoc2013-evolution-b4d89f6bbcff72bdb3f4670be8f632bf8b1c2a3c.tar.bz2 gsoc2013-evolution-b4d89f6bbcff72bdb3f4670be8f632bf8b1c2a3c.tar.lz gsoc2013-evolution-b4d89f6bbcff72bdb3f4670be8f632bf8b1c2a3c.tar.xz gsoc2013-evolution-b4d89f6bbcff72bdb3f4670be8f632bf8b1c2a3c.tar.zst gsoc2013-evolution-b4d89f6bbcff72bdb3f4670be8f632bf8b1c2a3c.zip |
oops, put the mempool stuff back, we don't use e-memory afterall. Damn
2003-11-14 Not Zed <NotZed@Ximian.com>
* camel-mime-parser.c (SCAN_BUF): oops, put the mempool stuff
back, we don't use e-memory afterall. Damn plane hacking.
svn path=/trunk/; revision=23344
Diffstat (limited to 'camel/camel-mime-parser.c')
-rw-r--r-- | camel/camel-mime-parser.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/camel/camel-mime-parser.c b/camel/camel-mime-parser.c index 214b48bc33..d3954c069c 100644 --- a/camel/camel-mime-parser.c +++ b/camel/camel-mime-parser.c @@ -71,6 +71,115 @@ int inend_id = -1, #define _header_scan_state _CamelMimeParserPrivate #define _PRIVATE(o) (((CamelMimeParser *)(o))->priv) +#ifdef MEMPOOL +typedef struct _MemPoolNode { + struct _MemPoolNode *next; + + int free; + char data[1]; +} MemPoolNode; + +typedef struct _MemPoolThresholdNode { + struct _MemPoolThresholdNode *next; + char data[1]; +} MemPoolThresholdNode; + +typedef struct _MemPool { + int blocksize; + int threshold; + struct _MemPoolNode *blocks; + struct _MemPoolThresholdNode *threshold_blocks; +} MemPool; + +MemPool *mempool_new(int blocksize, int threshold); +void *mempool_alloc(MemPool *pool, int size); +void mempool_flush(MemPool *pool, int freeall); +void mempool_free(MemPool *pool); + +MemPool *mempool_new(int blocksize, int threshold) +{ + MemPool *pool; + + pool = g_malloc(sizeof(*pool)); + if (threshold >= blocksize) + threshold = blocksize * 2 / 3; + pool->blocksize = blocksize; + pool->threshold = threshold; + pool->blocks = NULL; + pool->threshold_blocks = NULL; + return pool; +} + +void *mempool_alloc(MemPool *pool, int size) +{ + size = (size + STRUCT_ALIGN) & (~(STRUCT_ALIGN-1)); + if (size>=pool->threshold) { + MemPoolThresholdNode *n; + + n = g_malloc(sizeof(*n) - sizeof(char) + size); + n->next = pool->threshold_blocks; + pool->threshold_blocks = n; + return &n->data[0]; + } else { + MemPoolNode *n; + + n = pool->blocks; + while (n) { + if (n->free >= size) { + n->free -= size; + return &n->data[n->free]; + } + n = n->next; + } + + n = g_malloc(sizeof(*n) - sizeof(char) + pool->blocksize); + n->next = pool->blocks; + pool->blocks = n; + n->free = pool->blocksize - size; + return &n->data[n->free]; + } +} + +void mempool_flush(MemPool *pool, int freeall) +{ + MemPoolThresholdNode *tn, *tw; + MemPoolNode *pw, *pn; + + tw = pool->threshold_blocks; + while (tw) { + tn = tw->next; + g_free(tw); + tw = tn; + } + pool->threshold_blocks = NULL; + + if (freeall) { + pw = pool->blocks; + while (pw) { + pn = pw->next; + g_free(pw); + pw = pn; + } + pool->blocks = NULL; + } else { + pw = pool->blocks; + while (pw) { + pw->free = pool->blocksize; + pw = pw->next; + } + } +} + +void mempool_free(MemPool *pool) +{ + if (pool) { + mempool_flush(pool, 1); + g_free(pool); + } +} + +#endif + struct _header_scan_state { /* global state */ |