Index: /trunk/utils.c
===================================================================
--- /trunk/utils.c	(revision 343)
+++ /trunk/utils.c	(revision 344)
@@ -1,4 +1,6 @@
 
 #include "xcache.h"
+#include "stack.h"
+#include "xcache_globals.h"
 #include "utils.h"
 #ifdef ZEND_ENGINE_2_1
@@ -531,4 +533,7 @@
 {
 	HashTable *h;
+	zend_function tmp_func;
+	xc_cest_t tmp_cest;
+
 	if (sandbox) {
 		memset(sandbox, 0, sizeof(sandbox[0]));
@@ -567,6 +572,12 @@
 	h = OG(function_table);
 	zend_hash_init_ex(&TG(function_table), 128, NULL, h->pDestructor, h->persistent, h->bApplyProtection);
+	zend_hash_copy(&TG(function_table), &XG(internal_function_table), NULL, (void *) &tmp_func, sizeof(tmp_func));
+	TG(internal_class_tail) = TG(function_table).pListTail;
+
 	h = OG(class_table);
 	zend_hash_init_ex(&TG(class_table),     16, NULL, h->pDestructor, h->persistent, h->bApplyProtection);
+	zend_hash_copy(&TG(class_table), &XG(internal_class_table), NULL, (void *) &tmp_cest, sizeof(tmp_cest));
+	TG(internal_class_tail) = TG(class_table).pListTail;
+
 #ifdef ZEND_ENGINE_2_1
 	/* shallow copy, don't destruct */
@@ -613,5 +624,5 @@
 #endif
 
-	b = TG(function_table).pListHead;
+	b = TG(internal_function_tail) ? TG(internal_function_tail)->pListNext : TG(function_table).pListHead;
 	/* install function */
 	while (b != NULL) {
@@ -622,5 +633,5 @@
 	}
 
-	b = TG(class_table).pListHead;
+	b = TG(internal_class_tail) ? TG(internal_class_tail)->pListNext : TG(class_table).pListHead;
 	/* install class */
 	while (b != NULL) {
Index: /trunk/utils.h
===================================================================
--- /trunk/utils.h	(revision 343)
+++ /trunk/utils.h	(revision 344)
@@ -71,4 +71,6 @@
 	HashTable tmp_class_table;
 	HashTable tmp_auto_globals;
+	Bucket    *tmp_internal_function_tail;
+	Bucket    *tmp_internal_class_tail;
 } xc_sandbox_t;
 
Index: /trunk/xcache.c
===================================================================
--- /trunk/xcache.c	(revision 343)
+++ /trunk/xcache.c	(revision 344)
@@ -1025,12 +1025,14 @@
 		Bucket *b;
 		unsigned int i;
+		unsigned int j;
 
 #define COPY_H(vartype, var, cnt, name, datatype) do {        \
-	for (i = 0; b; i ++, b = b->pListNext) {                  \
-		vartype *data = &php->var[i];                         \
+	for (i = 0, j = 0; b; i ++, b = b->pListNext) {           \
+		vartype *data = &php->var[j];                         \
                                                               \
 		if (i < old_##cnt) {                                  \
 			continue;                                         \
 		}                                                     \
+		j ++;                                                 \
                                                               \
 		assert(i < old_##cnt + php->cnt);                     \
@@ -1603,4 +1605,14 @@
 	int i;
 
+	if (XG(internal_function_table).nTableSize == 0) {
+		zend_function tmp_func;
+		xc_cest_t tmp_cest;
+
+		zend_hash_init_ex(&XG(internal_function_table), 100, NULL, NULL, 1, 0);
+		zend_hash_copy(&XG(internal_function_table), CG(function_table), NULL, &tmp_func, sizeof(tmp_func));
+
+		zend_hash_init_ex(&XG(internal_class_table), 10, NULL, NULL, 1, 0);
+		zend_hash_copy(&XG(internal_class_table), CG(class_table), NULL, &tmp_cest, sizeof(tmp_cest));
+	}
 	if (xc_php_hcache.size && !XG(php_holds)) {
 		XG(php_holds) = calloc(xc_php_hcache.size, sizeof(xc_stack_t));
@@ -1676,4 +1688,7 @@
 		xcache_globals->var_holds = NULL;
 	}
+
+	zend_hash_destroy(&xcache_globals->internal_function_table);
+	zend_hash_destroy(&xcache_globals->internal_class_table);
 }
 /* }}} */
Index: /trunk/xcache_globals.h
===================================================================
--- /trunk/xcache_globals.h	(revision 343)
+++ /trunk/xcache_globals.h	(revision 344)
@@ -15,4 +15,7 @@
 	time_t request_time;
 	long   var_ttl;
+
+	HashTable internal_function_table;
+	HashTable internal_class_table;
 ZEND_END_MODULE_GLOBALS(xcache)
 
