summaryrefslogtreecommitdiff
path: root/ext/mysqlnd/mysqlnd_block_alloc.c
diff options
context:
space:
mode:
authorAndrey Hristov <andrey@php.net>2009-06-16 09:15:38 +0000
committerAndrey Hristov <andrey@php.net>2009-06-16 09:15:38 +0000
commit27270621cbcf8d2e7f6521f505499b91e45cdc82 (patch)
tree9559ccfa0f25a033935ed468eb07fa5869ba9284 /ext/mysqlnd/mysqlnd_block_alloc.c
parentf0f302fe7fe1fd78623e3a6527410d1e28801efe (diff)
downloadphp-git-27270621cbcf8d2e7f6521f505499b91e45cdc82.tar.gz
MFH:
Hardwire function call instead of using callbacks. We don't actually need callbacks, it was done for making 2 functions static, not to pollute the global functions space but that had its price of 8 bytes overheat per allocation, which is just too much. Also making the app member 32b instead of 64b, which should save additional 4 byte, to the total of 12 byte per allocation of a row buffer.
Diffstat (limited to 'ext/mysqlnd/mysqlnd_block_alloc.c')
-rw-r--r--ext/mysqlnd/mysqlnd_block_alloc.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/ext/mysqlnd/mysqlnd_block_alloc.c b/ext/mysqlnd/mysqlnd_block_alloc.c
index 4943624f47..19442c5970 100644
--- a/ext/mysqlnd/mysqlnd_block_alloc.c
+++ b/ext/mysqlnd/mysqlnd_block_alloc.c
@@ -35,7 +35,7 @@ mysqlnd_mempool_free_contents(MYSQLND_MEMORY_POOL * pool TSRMLS_DC)
DBG_ENTER("mysqlnd_mempool_dtor");
for (i = 0; i < pool->free_chunk_list_elements; i++) {
MYSQLND_MEMORY_POOL_CHUNK * chunk = pool->free_chunk_list[i];
- chunk->free_chunk(chunk, FALSE TSRMLS_CC);
+ mysqlnd_mempool_free_chunk(chunk, FALSE TSRMLS_CC);
}
DBG_VOID_RETURN;
@@ -44,11 +44,14 @@ mysqlnd_mempool_free_contents(MYSQLND_MEMORY_POOL * pool TSRMLS_DC)
/* {{{ mysqlnd_mempool_free_chunk */
-static void
+void
mysqlnd_mempool_free_chunk(MYSQLND_MEMORY_POOL_CHUNK * chunk, zend_bool cache_it TSRMLS_DC)
{
MYSQLND_MEMORY_POOL * pool = chunk->pool;
DBG_ENTER("mysqlnd_mempool_free_chunk");
+ if (!chunk) {
+ DBG_VOID_RETURN;
+ }
if (chunk->from_pool) {
/* Try to back-off and guess if this is the last block allocated */
if (chunk->ptr == (pool->arena + (pool->arena_size - pool->free_size - chunk->size))) {
@@ -60,14 +63,14 @@ mysqlnd_mempool_free_chunk(MYSQLND_MEMORY_POOL_CHUNK * chunk, zend_bool cache_it
}
pool->refcount--;
} else {
- mnd_free(chunk->ptr);
+ mnd_efree(chunk->ptr);
}
if (cache_it && pool->free_chunk_list_elements < MYSQLND_MEMORY_POOL_CHUNK_LIST_SIZE) {
chunk->ptr = NULL;
pool->free_chunk_list[pool->free_chunk_list_elements++] = chunk;
} else {
/* We did not cache it -> free it */
- mnd_free(chunk);
+ mnd_efree(chunk);
}
DBG_VOID_RETURN;
}
@@ -75,7 +78,7 @@ mysqlnd_mempool_free_chunk(MYSQLND_MEMORY_POOL_CHUNK * chunk, zend_bool cache_it
/* {{{ mysqlnd_mempool_resize_chunk */
-static void
+void
mysqlnd_mempool_resize_chunk(MYSQLND_MEMORY_POOL_CHUNK * chunk, unsigned int size TSRMLS_DC)
{
DBG_ENTER("mysqlnd_mempool_resize_chunk");
@@ -132,11 +135,9 @@ MYSQLND_MEMORY_POOL_CHUNK * mysqlnd_mempool_get_chunk(MYSQLND_MEMORY_POOL * pool
if (pool->free_chunk_list_elements) {
chunk = pool->free_chunk_list[--pool->free_chunk_list_elements];
} else {
- chunk = mnd_malloc(sizeof(MYSQLND_MEMORY_POOL_CHUNK));
+ chunk = mnd_emalloc(sizeof(MYSQLND_MEMORY_POOL_CHUNK));
}
- chunk->free_chunk = mysqlnd_mempool_free_chunk;
- chunk->resize_chunk = mysqlnd_mempool_resize_chunk;
chunk->size = size;
/*
Should not go over MYSQLND_MAX_PACKET_SIZE, since we
@@ -145,7 +146,7 @@ MYSQLND_MEMORY_POOL_CHUNK * mysqlnd_mempool_get_chunk(MYSQLND_MEMORY_POOL * pool
*/
chunk->pool = pool;
if (size > pool->free_size) {
- chunk->ptr = mnd_malloc(size);
+ chunk->ptr = mnd_emalloc(size);
chunk->from_pool = FALSE;
} else {
chunk->from_pool = TRUE;
@@ -164,13 +165,13 @@ MYSQLND_MEMORY_POOL *
mysqlnd_mempool_create(size_t arena_size TSRMLS_DC)
{
/* We calloc, because we free(). We don't mnd_calloc() for a reason. */
- MYSQLND_MEMORY_POOL * ret = mnd_calloc(1, sizeof(MYSQLND_MEMORY_POOL));
+ MYSQLND_MEMORY_POOL * ret = mnd_ecalloc(1, sizeof(MYSQLND_MEMORY_POOL));
DBG_ENTER("mysqlnd_mempool_create");
ret->free_size = ret->arena_size = arena_size;
ret->refcount = 0;
/* OOM ? */
- ret->arena = mnd_malloc(ret->arena_size);
+ ret->arena = mnd_emalloc(ret->arena_size);
ret->get_chunk = mysqlnd_mempool_get_chunk;
DBG_RETURN(ret);
@@ -186,8 +187,8 @@ mysqlnd_mempool_destroy(MYSQLND_MEMORY_POOL * pool TSRMLS_DC)
if (pool) {
/* mnd_free will reference LOCK_access and might crash, depending on the caller...*/
mysqlnd_mempool_free_contents(pool TSRMLS_CC);
- mnd_free(pool->arena);
- mnd_free(pool);
+ mnd_efree(pool->arena);
+ mnd_efree(pool);
}
DBG_VOID_RETURN;
}