zend_fast_hash
| From: | Sterling Hughes | Date: | Wed, 21 May 2003 13:33:39 +0000 |
| Subject: | zend_fast_hash | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-1853@lists.php.net to get a copy of this message | ||
Hi,
I've implemented a very lightweight, efficient hash table for zend
engine 2. This is a table that's appropriate for usage in many of the
areas where then Zend hash table implementation is unnecessarily complex
(which is pretty much everywhere except for PHP arrays themselves.)
I've attached the implementation, and a patch which integrates the new
hashtable implementation with Zend, including a "case-study," where I've
converted over EG(included_files) to use the new hashtable
implementation. Right now the hash table code is very simple, as its
just there for initial perusal, it can of course be improved upon.
So, when can I integrate it? ;-)
-Sterling
--
"A business that makes nothing but money is a poor kind of business."
- Henry Ford
? fast_hash ? fast_hash.diff ? zend_fast_hash.c ? zend_fast_hash.h Index: Makefile.am =================================================================== RCS file: /repository/ZendEngine2/Makefile.am,v retrieving revision 1.52 diff -u -r1.52 Makefile.am --- Makefile.am 23 Mar 2003 04:32:23 -0000 1.52 +++ Makefile.am 21 May 2003 14:53:41 -0000 @@ -14,7 +14,7 @@ zend_variables.c zend.c zend_API.c zend_extensions.c zend_hash.c \ zend_list.c zend_indent.c zend_builtin_functions.c zend_sprintf.c \ zend_ini.c zend_qsort.c zend_objects.c zend_object_handlers.c \ - zend_objects_API.c zend_ts_hash.c zend_stream.c zend_mm.c zend_default_classes.c + zend_objects_API.c zend_ts_hash.c zend_stream.c zend_mm.c zend_default_classes.c zend_fast_hash.c libZend_la_LDFLAGS = libZend_la_LIBADD = @ZEND_EXTRA_LIBS@ Index: zend_builtin_functions.c =================================================================== RCS file: /repository/ZendEngine2/zend_builtin_functions.c,v retrieving revision 1.187 diff -u -r1.187 zend_builtin_functions.c --- zend_builtin_functions.c 21 Apr 2003 17:01:34 -0000 1.187 +++ zend_builtin_functions.c 21 May 2003 14:53:46 -0000 @@ -24,6 +24,7 @@ #include "zend_builtin_functions.h" #include "zend_constants.h" #include "zend_ini.h" +#include "zend_fast_hash.h" #undef ZEND_TEST_EXCEPTIONS @@ -944,16 +945,23 @@ Returns an array with the file names that were include_once()'d */ ZEND_FUNCTION(get_included_files) { - char *entry; + zend_fast_hash *files; + zend_fast_hash_slist *current; + int i; + if (ZEND_NUM_ARGS() != 0) { ZEND_WRONG_PARAM_COUNT(); } array_init(return_value); - zend_hash_internal_pointer_reset(&EG(included_files)); - while (zend_hash_get_current_key(&EG(included_files), &entry, NULL, 1) == HASH_KEY_IS_STRING) { - add_next_index_string(return_value, entry, 0); - zend_hash_move_forward(&EG(included_files)); + + files = (zend_fast_hash *) &EG(included_files); + for (i = 0; i < files->slots; ++i) { + current = files->table[i]; + while (current) { + add_next_index_string(return_value, current->key, 0); + current = current->next; + } } } /* }}} */ Index: zend_execute.c =================================================================== RCS file: /repository/ZendEngine2/zend_execute.c,v retrieving revision 1.462 diff -u -r1.462 zend_execute.c --- zend_execute.c 21 May 2003 11:48:55 -0000 1.462 +++ zend_execute.c 21 May 2003 14:53:54 -0000 @@ -3383,7 +3383,7 @@ file_handle.opened_path = estrndup(inc_filename->value.str.val, inc_filename->value.str.len); } - if (zend_hash_add(&EG(included_files), file_handle.opened_path, strlen(file_handle.opened_path)+1, (void *)&dummy, sizeof(int), NULL)==SUCCESS) { + if (zend_fast_hash_update(&EG(included_files), file_handle.opened_path, strlen(file_handle.opened_path)+1, (void *)&dummy TSRMLS_CC)==SUCCESS) { CG(active_namespace) = EG(global_namespace_ptr); new_op_array = zend_compile_file(&file_handle, (EX(opline)->op2.u.constant.value.lval==ZEND_INCLUDE_ONCE?ZEND_INCLUDE:ZEND_REQUIRE) TSRMLS_CC); zend_destroy_file_handle(&file_handle TSRMLS_CC); Index: zend_execute_API.c =================================================================== RCS file: /repository/ZendEngine2/zend_execute_API.c,v retrieving revision 1.204 diff -u -r1.204 zend_execute_API.c --- zend_execute_API.c 20 May 2003 18:28:14 -0000 1.204 +++ zend_execute_API.c 21 May 2003 14:53:56 -0000 @@ -156,7 +156,7 @@ EG(opline_ptr) = NULL; EG(garbage_ptr) = 0; - zend_hash_init(&EG(included_files), 5, NULL, NULL, 0); + zend_fast_hash_init(&EG(included_files), 5, 0, NULL TSRMLS_CC); EG(ticks_count) = 0; @@ -269,7 +269,7 @@ signal(SIGSEGV, original_sigsegv_handler); #endif - zend_hash_destroy(&EG(included_files)); + zend_fast_hash_destroy(&EG(included_files)); if (EG(user_error_handler)) { zval_dtor(EG(user_error_handler)); Attachment: [text/x-c] zend_fast_hash.c
Attachment: [text/x-c-header] zend_fast_hash.h
? fast_hash ? fast_hash.diff ? zend_fast_hash.c ? zend_fast_hash.h Index: Makefile.am =================================================================== RCS file: /repository/ZendEngine2/Makefile.am,v retrieving revision 1.52 diff -u -r1.52 Makefile.am --- Makefile.am 23 Mar 2003 04:32:23 -0000 1.52 +++ Makefile.am 21 May 2003 14:53:41 -0000 @@ -14,7 +14,7 @@ zend_variables.c zend.c zend_API.c zend_extensions.c zend_hash.c \ zend_list.c zend_indent.c zend_builtin_functions.c zend_sprintf.c \ zend_ini.c zend_qsort.c zend_objects.c zend_object_handlers.c \ - zend_objects_API.c zend_ts_hash.c zend_stream.c zend_mm.c zend_default_classes.c + zend_objects_API.c zend_ts_hash.c zend_stream.c zend_mm.c zend_default_classes.c zend_fast_hash.c libZend_la_LDFLAGS = libZend_la_LIBADD = @ZEND_EXTRA_LIBS@ Index: zend_builtin_functions.c =================================================================== RCS file: /repository/ZendEngine2/zend_builtin_functions.c,v retrieving revision 1.187 diff -u -r1.187 zend_builtin_functions.c --- zend_builtin_functions.c 21 Apr 2003 17:01:34 -0000 1.187 +++ zend_builtin_functions.c 21 May 2003 14:53:46 -0000 @@ -24,6 +24,7 @@ #include "zend_builtin_functions.h" #include "zend_constants.h" #include "zend_ini.h" +#include "zend_fast_hash.h" #undef ZEND_TEST_EXCEPTIONS @@ -944,16 +945,23 @@ Returns an array with the file names that were include_once()'d */ ZEND_FUNCTION(get_included_files) { - char *entry; + zend_fast_hash *files; + zend_fast_hash_slist *current; + int i; + if (ZEND_NUM_ARGS() != 0) { ZEND_WRONG_PARAM_COUNT(); } array_init(return_value); - zend_hash_internal_pointer_reset(&EG(included_files)); - while (zend_hash_get_current_key(&EG(included_files), &entry, NULL, 1) == HASH_KEY_IS_STRING) { - add_next_index_string(return_value, entry, 0); - zend_hash_move_forward(&EG(included_files)); + + files = (zend_fast_hash *) &EG(included_files); + for (i = 0; i < files->slots; ++i) { + current = files->table[i]; + while (current) { + add_next_index_string(return_value, current->key, 0); + current = current->next; + } } } /* }}} */ Index: zend_execute.c =================================================================== RCS file: /repository/ZendEngine2/zend_execute.c,v retrieving revision 1.462 diff -u -r1.462 zend_execute.c --- zend_execute.c 21 May 2003 11:48:55 -0000 1.462 +++ zend_execute.c 21 May 2003 14:53:54 -0000 @@ -3383,7 +3383,7 @@ file_handle.opened_path = estrndup(inc_filename->value.str.val, inc_filename->value.str.len); } - if (zend_hash_add(&EG(included_files), file_handle.opened_path, strlen(file_handle.opened_path)+1, (void *)&dummy, sizeof(int), NULL)==SUCCESS) { + if (zend_fast_hash_update(&EG(included_files), file_handle.opened_path, strlen(file_handle.opened_path)+1, (void *)&dummy TSRMLS_CC)==SUCCESS) { CG(active_namespace) = EG(global_namespace_ptr); new_op_array = zend_compile_file(&file_handle, (EX(opline)->op2.u.constant.value.lval==ZEND_INCLUDE_ONCE?ZEND_INCLUDE:ZEND_REQUIRE) TSRMLS_CC); zend_destroy_file_handle(&file_handle TSRMLS_CC); Index: zend_execute_API.c =================================================================== RCS file: /repository/ZendEngine2/zend_execute_API.c,v retrieving revision 1.204 diff -u -r1.204 zend_execute_API.c --- zend_execute_API.c 20 May 2003 18:28:14 -0000 1.204 +++ zend_execute_API.c 21 May 2003 14:53:56 -0000 @@ -156,7 +156,7 @@ EG(opline_ptr) = NULL; EG(garbage_ptr) = 0; - zend_hash_init(&EG(included_files), 5, NULL, NULL, 0); + zend_fast_hash_init(&EG(included_files), 5, 0, NULL TSRMLS_CC); EG(ticks_count) = 0; @@ -269,7 +269,7 @@ signal(SIGSEGV, original_sigsegv_handler); #endif - zend_hash_destroy(&EG(included_files)); + zend_fast_hash_destroy(&EG(included_files)); if (EG(user_error_handler)) { zval_dtor(EG(user_error_handler)); Attachment: [text/x-c] zend_fast_hash.c
Attachment: [text/x-c-header] zend_fast_hash.h