summaryrefslogtreecommitdiff
path: root/ext/opcache/zend_accelerator_hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/opcache/zend_accelerator_hash.c')
-rw-r--r--ext/opcache/zend_accelerator_hash.c66
1 files changed, 14 insertions, 52 deletions
diff --git a/ext/opcache/zend_accelerator_hash.c b/ext/opcache/zend_accelerator_hash.c
index 7cd9ef1ef4..a39b6a3ecf 100644
--- a/ext/opcache/zend_accelerator_hash.c
+++ b/ext/opcache/zend_accelerator_hash.c
@@ -54,14 +54,14 @@ void zend_accel_hash_init(zend_accel_hash *accel_hash, uint32_t hash_size)
/* set up hash pointers table */
accel_hash->hash_table = zend_shared_alloc(sizeof(zend_accel_hash_entry *)*accel_hash->max_num_entries);
if (!accel_hash->hash_table) {
- zend_accel_error(ACCEL_LOG_FATAL, "Insufficient shared memory!");
+ zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Insufficient shared memory!");
return;
}
/* set up hash values table */
accel_hash->hash_entries = zend_shared_alloc(sizeof(zend_accel_hash_entry)*accel_hash->max_num_entries);
if (!accel_hash->hash_entries) {
- zend_accel_error(ACCEL_LOG_FATAL, "Insufficient shared memory!");
+ zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Insufficient shared memory!");
return;
}
memset(accel_hash->hash_table, 0, sizeof(zend_accel_hash_entry *)*accel_hash->max_num_entries);
@@ -71,7 +71,7 @@ void zend_accel_hash_init(zend_accel_hash *accel_hash, uint32_t hash_size)
* Returns pointer the actual hash entry on success
* key needs to be already allocated as it is not copied
*/
-zend_accel_hash_entry* zend_accel_hash_update(zend_accel_hash *accel_hash, const char *key, uint32_t key_length, zend_bool indirect, void *data)
+zend_accel_hash_entry* zend_accel_hash_update(zend_accel_hash *accel_hash, zend_string *key, bool indirect, void *data)
{
zend_ulong hash_value;
zend_ulong index;
@@ -85,7 +85,7 @@ zend_accel_hash_entry* zend_accel_hash_update(zend_accel_hash *accel_hash, const
}
}
- hash_value = zend_inline_hash_func(key, key_length);
+ hash_value = zend_string_hash_val(key);
#ifndef ZEND_WIN32
hash_value ^= ZCG(root_hash);
#endif
@@ -95,8 +95,7 @@ zend_accel_hash_entry* zend_accel_hash_update(zend_accel_hash *accel_hash, const
entry = accel_hash->hash_table[index];
while (entry) {
if (entry->hash_value == hash_value
- && entry->key_length == key_length
- && !memcmp(entry->key, key, key_length)) {
+ && zend_string_equals(entry->key, key)) {
if (entry->indirect) {
if (indirect_bucket) {
@@ -134,17 +133,18 @@ zend_accel_hash_entry* zend_accel_hash_update(zend_accel_hash *accel_hash, const
}
entry->hash_value = hash_value;
entry->key = key;
- entry->key_length = key_length;
entry->next = accel_hash->hash_table[index];
accel_hash->hash_table[index] = entry;
return entry;
}
-static zend_always_inline void* zend_accel_hash_find_ex(zend_accel_hash *accel_hash, const char *key, uint32_t key_length, zend_ulong hash_value, int data)
+static zend_always_inline void* zend_accel_hash_find_ex(zend_accel_hash *accel_hash, zend_string *key, int data)
{
zend_ulong index;
zend_accel_hash_entry *entry;
+ zend_ulong hash_value;
+ hash_value = zend_string_hash_val(key);
#ifndef ZEND_WIN32
hash_value ^= ZCG(root_hash);
#endif
@@ -153,8 +153,7 @@ static zend_always_inline void* zend_accel_hash_find_ex(zend_accel_hash *accel_h
entry = accel_hash->hash_table[index];
while (entry) {
if (entry->hash_value == hash_value
- && entry->key_length == key_length
- && !memcmp(entry->key, key, key_length)) {
+ && zend_string_equals(entry->key, key)) {
if (entry->indirect) {
if (data) {
return ((zend_accel_hash_entry*)entry->data)->data;
@@ -179,12 +178,7 @@ static zend_always_inline void* zend_accel_hash_find_ex(zend_accel_hash *accel_h
*/
void* zend_accel_hash_find(zend_accel_hash *accel_hash, zend_string *key)
{
- return zend_accel_hash_find_ex(
- accel_hash,
- ZSTR_VAL(key),
- ZSTR_LEN(key),
- zend_string_hash_val(key),
- 1);
+ return zend_accel_hash_find_ex(accel_hash, key, 1);
}
/* Returns the hash entry associated with key on success
@@ -192,47 +186,16 @@ void* zend_accel_hash_find(zend_accel_hash *accel_hash, zend_string *key)
*/
zend_accel_hash_entry* zend_accel_hash_find_entry(zend_accel_hash *accel_hash, zend_string *key)
{
- return (zend_accel_hash_entry *)zend_accel_hash_find_ex(
- accel_hash,
- ZSTR_VAL(key),
- ZSTR_LEN(key),
- zend_string_hash_val(key),
- 0);
-}
-
-/* Returns the data associated with key on success
- * Returns NULL if data doesn't exist
- */
-void* zend_accel_hash_str_find(zend_accel_hash *accel_hash, const char *key, uint32_t key_length)
-{
- return zend_accel_hash_find_ex(
- accel_hash,
- key,
- key_length,
- zend_inline_hash_func(key, key_length),
- 1);
-}
-
-/* Returns the hash entry associated with key on success
- * Returns NULL if it doesn't exist
- */
-zend_accel_hash_entry* zend_accel_hash_str_find_entry(zend_accel_hash *accel_hash, const char *key, uint32_t key_length)
-{
- return (zend_accel_hash_entry *)zend_accel_hash_find_ex(
- accel_hash,
- key,
- key_length,
- zend_inline_hash_func(key, key_length),
- 0);
+ return (zend_accel_hash_entry *)zend_accel_hash_find_ex(accel_hash, key, 0);
}
-int zend_accel_hash_unlink(zend_accel_hash *accel_hash, const char *key, uint32_t key_length)
+int zend_accel_hash_unlink(zend_accel_hash *accel_hash, zend_string *key)
{
zend_ulong hash_value;
zend_ulong index;
zend_accel_hash_entry *entry, *last_entry=NULL;
- hash_value = zend_inline_hash_func(key, key_length);
+ hash_value = zend_string_hash_val(key);
#ifndef ZEND_WIN32
hash_value ^= ZCG(root_hash);
#endif
@@ -241,8 +204,7 @@ int zend_accel_hash_unlink(zend_accel_hash *accel_hash, const char *key, uint32_
entry = accel_hash->hash_table[index];
while (entry) {
if (entry->hash_value == hash_value
- && entry->key_length == key_length
- && !memcmp(entry->key, key, key_length)) {
+ && zend_string_equals(entry->key, key)) {
if (!entry->indirect) {
accel_hash->num_direct_entries--;
}