Back to index

php5  5.3.10
zend_fast_cache.h
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | Zend Engine                                                          |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1998-2012 Zend Technologies Ltd. (http://www.zend.com) |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 2.00 of the Zend license,     |
00008    | that is bundled with this package in the file LICENSE, and is        | 
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.zend.com/license/2_00.txt.                                |
00011    | If you did not receive a copy of the Zend license and are unable to  |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@zend.com so we can mail you a copy immediately.              |
00014    +----------------------------------------------------------------------+
00015    | Authors: Andi Gutmans <andi@zend.com>                                |
00016    |          Zeev Suraski <zeev@zend.com>                                |
00017    +----------------------------------------------------------------------+
00018 */
00019 
00020 /* $Id: zend_fast_cache.h 321634 2012-01-01 13:15:04Z felipe $ */
00021 #if 0
00022 #ifndef ZEND_FAST_CACHE_H
00023 #define ZEND_FAST_CACHE_H
00024 
00025 #ifndef ZEND_ENABLE_FAST_CACHE
00026 # if ZEND_DEBUG
00027 # define ZEND_ENABLE_FAST_CACHE 0
00028 # else
00029 # define ZEND_ENABLE_FAST_CACHE 0
00030 # endif
00031 #endif
00032 
00033 typedef struct _zend_fast_cache_list_entry {
00034        struct _zend_fast_cache_list_entry *next;
00035 } zend_fast_cache_list_entry;
00036 
00037 #define MAX_FAST_CACHE_TYPES       4
00038 
00039 
00040 #define ZVAL_CACHE_LIST                   0
00041 #define HASHTABLE_CACHE_LIST       1
00042 
00043 #if ZEND_ENABLE_FAST_CACHE
00044 
00045 
00046 #include "zend_globals.h"
00047 #include "zend_globals_macros.h"
00048 #include "zend_alloc.h"
00049 
00050 
00051 #if ZEND_DEBUG
00052 # define RECORD_ZVAL_CACHE_HIT(fc_type)          AG(fast_cache_stats)[fc_type][1]++;
00053 # define RECORD_ZVAL_CACHE_MISS(fc_type)  AG(fast_cache_stats)[fc_type][0]++;
00054 #else
00055 # define RECORD_ZVAL_CACHE_HIT(fc_type)
00056 # define RECORD_ZVAL_CACHE_MISS(fc_type)
00057 #endif
00058 
00059 
00060 #define ZEND_FAST_ALLOC(p, type, fc_type)                                                  \
00061        {                                                                                                               \
00062               TSRMLS_FETCH();                                                                                   \
00063                                                                                                                        \
00064               if (((p) = (type *) AG(fast_cache_list_head)[fc_type])) {      \
00065                      AG(fast_cache_list_head)[fc_type] = ((zend_fast_cache_list_entry *) AG(fast_cache_list_head)[fc_type])->next;   \
00066                      RECORD_ZVAL_CACHE_HIT(fc_type);                                              \
00067               } else {                                                                                          \
00068                      (p) = (type *) emalloc(sizeof(type));                                 \
00069                      RECORD_ZVAL_CACHE_MISS(fc_type);                                      \
00070               }                                                                                                        \
00071        }
00072 
00073 
00074 #define ZEND_FAST_FREE(p, fc_type)                                                                \
00075        {                                                                                                               \
00076               TSRMLS_FETCH();                                                                                   \
00077                                                                                                                        \
00078               ((zend_fast_cache_list_entry *) (p))->next = (zend_fast_cache_list_entry *) AG(fast_cache_list_head)[fc_type];  \
00079               AG(fast_cache_list_head)[fc_type] = (zend_fast_cache_list_entry *) (p);                    \
00080        }
00081 
00082 #define ZEND_FAST_ALLOC_REL(p, type, fc_type)    \
00083        ZEND_FAST_ALLOC(p, type, fc_type)
00084 
00085 #define ZEND_FAST_FREE_REL(p, fc_type)    \
00086        ZEND_FAST_FREE(p, fc_type)
00087 
00088 
00089 #else /* !ZEND_ENABLE_FAST_CACHE */
00090 
00091 #define ZEND_FAST_ALLOC(p, type, fc_type) \
00092        (p) = (type *) emalloc(sizeof(type))
00093 
00094 #define ZEND_FAST_FREE(p, fc_type) \
00095        efree(p)
00096 
00097 #define ZEND_FAST_ALLOC_REL(p, type, fc_type)    \
00098        (p) = (type *) emalloc_rel(sizeof(type))
00099 
00100 #define ZEND_FAST_FREE_REL(p, fc_type)    \
00101        efree_rel(p)
00102 
00103 #endif /* ZEND_ENABLE_FAST_CACHE */
00104 
00105 
00106 
00107 /* fast cache for zval's */
00108 #define ALLOC_ZVAL(z)       \
00109        ZEND_FAST_ALLOC(z, zval, ZVAL_CACHE_LIST)
00110 
00111 #define FREE_ZVAL(z) \
00112        ZEND_FAST_FREE(z, ZVAL_CACHE_LIST)
00113 
00114 #define ALLOC_ZVAL_REL(z)   \
00115        ZEND_FAST_ALLOC_REL(z, zval, ZVAL_CACHE_LIST)
00116 
00117 #define FREE_ZVAL_REL(z)    \
00118        ZEND_FAST_FREE_REL(z, ZVAL_CACHE_LIST)
00119 
00120 /* fast cache for HashTables */
00121 #define ALLOC_HASHTABLE(ht) \
00122        ZEND_FAST_ALLOC(ht, HashTable, HASHTABLE_CACHE_LIST)
00123 
00124 #define FREE_HASHTABLE(ht)  \
00125        ZEND_FAST_FREE(ht, HASHTABLE_CACHE_LIST)
00126 
00127 #define ALLOC_HASHTABLE_REL(ht)    \
00128        ZEND_FAST_ALLOC_REL(ht, HashTable, HASHTABLE_CACHE_LIST)
00129 
00130 #define FREE_HASHTABLE_REL(ht)     \
00131        ZEND_FAST_FREE_REL(ht, HASHTABLE_CACHE_LIST)
00132 
00133 #endif /* ZEND_FAST_CACHE_H */
00134 #endif
00135 /*
00136  * Local variables:
00137  * tab-width: 4
00138  * c-basic-offset: 4
00139  * indent-tabs-mode: t
00140  * End:
00141  */