summaryrefslogtreecommitdiff
path: root/ext/opcache
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2018-04-04 02:12:26 +0300
committerDmitry Stogov <dmitry@zend.com>2018-04-04 02:12:26 +0300
commit4df89a31b0cc6e4bdd76c8b7c4cf7d5676309d6e (patch)
tree45f555efaf3f8fd70df7c4a0cf95557011b1b23d /ext/opcache
parentcb464a53c8216dd76e14d21b74d6adecd5f002f8 (diff)
downloadphp-git-4df89a31b0cc6e4bdd76c8b7c4cf7d5676309d6e.tar.gz
Eliminate useless checks
Diffstat (limited to 'ext/opcache')
-rw-r--r--ext/opcache/zend_accelerator_util_funcs.c47
1 files changed, 41 insertions, 6 deletions
diff --git a/ext/opcache/zend_accelerator_util_funcs.c b/ext/opcache/zend_accelerator_util_funcs.c
index fe98d77d3b..a6d9b543a6 100644
--- a/ext/opcache/zend_accelerator_util_funcs.c
+++ b/ext/opcache/zend_accelerator_util_funcs.c
@@ -533,7 +533,7 @@ static void zend_accel_function_hash_copy_from_shm(HashTable *target, HashTable
goto failure;
}
} else {
- _zend_hash_append_ptr(target, p->key, ARENA_REALLOC(Z_PTR(p->val)));
+ _zend_hash_append_ptr_ex(target, p->key, ARENA_REALLOC(Z_PTR(p->val)), 1);
}
}
target->nInternalPointer = 0;
@@ -556,7 +556,7 @@ failure:
}
}
-static void zend_accel_class_hash_copy(HashTable *target, HashTable *source, unique_copy_ctor_func_t pCopyConstructor)
+static void zend_accel_class_hash_copy(HashTable *target, HashTable *source)
{
Bucket *p, *end;
zval *t;
@@ -587,9 +587,44 @@ static void zend_accel_class_hash_copy(HashTable *target, HashTable *source, uni
}
} else {
t = _zend_hash_append_ptr(target, p->key, Z_PTR(p->val));
- if (pCopyConstructor) {
- pCopyConstructor(&Z_PTR_P(t));
+ }
+ }
+ target->nInternalPointer = 0;
+ return;
+}
+
+static void zend_accel_class_hash_copy_from_shm(HashTable *target, HashTable *source)
+{
+ Bucket *p, *end;
+ zval *t;
+
+ zend_hash_extend(target, target->nNumUsed + source->nNumUsed, 0);
+ p = source->arData;
+ end = p + source->nNumUsed;
+ for (; p != end; p++) {
+ ZEND_ASSERT(Z_TYPE(p->val) != IS_UNDEF);
+ ZEND_ASSERT(p->key);
+ t = zend_hash_find_ex(target, p->key, 1);
+ if (UNEXPECTED(t != NULL)) {
+ if (EXPECTED(ZSTR_LEN(p->key) > 0) && EXPECTED(ZSTR_VAL(p->key)[0] == 0)) {
+ /* Mangled key - ignore and wait for runtime */
+ continue;
+ } else if (UNEXPECTED(!ZCG(accel_directives).ignore_dups)) {
+ zend_class_entry *ce1 = Z_PTR(p->val);
+ if (!(ce1->ce_flags & ZEND_ACC_ANON_CLASS)) {
+ CG(in_compilation) = 1;
+ zend_set_compiled_filename(ce1->info.user.filename);
+ CG(zend_lineno) = ce1->info.user.line_start;
+ zend_error(E_ERROR,
+ "Cannot declare %s %s, because the name is already in use",
+ zend_get_object_type(ce1), ZSTR_VAL(ce1->name));
+ return;
+ }
+ continue;
}
+ } else {
+ t = _zend_hash_append_ptr_ex(target, p->key, Z_PTR(p->val), 1);
+ zend_class_copy_ctor((zend_class_entry**)&Z_PTR_P(t));
}
}
target->nInternalPointer = 0;
@@ -771,7 +806,7 @@ zend_op_array* zend_accel_load_script(zend_persistent_script *persistent_script,
/* Copy all the necessary stuff from shared memory to regular memory, and protect the shared script */
if (zend_hash_num_elements(&persistent_script->script.class_table) > 0) {
- zend_accel_class_hash_copy(CG(class_table), &persistent_script->script.class_table, (unique_copy_ctor_func_t) zend_class_copy_ctor);
+ zend_accel_class_hash_copy_from_shm(CG(class_table), &persistent_script->script.class_table);
}
/* we must first to copy all classes and then prepare functions, since functions may try to bind
classes - which depend on pre-bind class entries existent in the class table */
@@ -799,7 +834,7 @@ zend_op_array* zend_accel_load_script(zend_persistent_script *persistent_script,
zend_accel_function_hash_copy(CG(function_table), &persistent_script->script.function_table);
}
if (zend_hash_num_elements(&persistent_script->script.class_table) > 0) {
- zend_accel_class_hash_copy(CG(class_table), &persistent_script->script.class_table, NULL);
+ zend_accel_class_hash_copy(CG(class_table), &persistent_script->script.class_table);
}
}