]> granicus.if.org Git - php/commitdiff
Simplify attribute persistence
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 17 Mar 2021 10:51:23 +0000 (11:51 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 17 Mar 2021 10:52:45 +0000 (11:52 +0100)
For an inherited op_array, directly fetch the xlat entry, as we
do for everything else.

ext/opcache/zend_persist.c

index 216b6a1eb09e37f03df8e38f77cf81c56a9380ac..1e410979014f92cff1aaba4e02b261f9e2fac72e 100644 (file)
@@ -259,40 +259,35 @@ static void zend_persist_zval(zval *z)
 
 static HashTable *zend_persist_attributes(HashTable *attributes)
 {
-       HashTable *ptr = zend_shared_alloc_get_xlat_entry(attributes);
-
-       if (!ptr) {
-               uint32_t i;
-               zval *v;
+       uint32_t i;
+       zval *v;
 
-               if (!ZCG(current_persistent_script)->corrupted
-                && zend_accel_in_shm(attributes)) {
-                       return attributes;
-               }
+       if (!ZCG(current_persistent_script)->corrupted && zend_accel_in_shm(attributes)) {
+               return attributes;
+       }
 
-               zend_hash_persist(attributes);
+       zend_hash_persist(attributes);
 
-               ZEND_HASH_FOREACH_VAL(attributes, v) {
-                       zend_attribute *attr = Z_PTR_P(v);
-                       zend_attribute *copy = zend_shared_memdup_put_free(attr, ZEND_ATTRIBUTE_SIZE(attr->argc));
+       ZEND_HASH_FOREACH_VAL(attributes, v) {
+               zend_attribute *attr = Z_PTR_P(v);
+               zend_attribute *copy = zend_shared_memdup_put_free(attr, ZEND_ATTRIBUTE_SIZE(attr->argc));
 
-                       zend_accel_store_interned_string(copy->name);
-                       zend_accel_store_interned_string(copy->lcname);
+               zend_accel_store_interned_string(copy->name);
+               zend_accel_store_interned_string(copy->lcname);
 
-                       for (i = 0; i < copy->argc; i++) {
-                               if (copy->args[i].name) {
-                                       zend_accel_store_interned_string(copy->args[i].name);
-                               }
-                               zend_persist_zval(&copy->args[i].value);
+               for (i = 0; i < copy->argc; i++) {
+                       if (copy->args[i].name) {
+                               zend_accel_store_interned_string(copy->args[i].name);
                        }
+                       zend_persist_zval(&copy->args[i].value);
+               }
 
-                       ZVAL_PTR(v, copy);
-               } ZEND_HASH_FOREACH_END();
+               ZVAL_PTR(v, copy);
+       } ZEND_HASH_FOREACH_END();
 
-               ptr = zend_shared_memdup_put_free(attributes, sizeof(HashTable));
-               GC_SET_REFCOUNT(ptr, 2);
-               GC_TYPE_INFO(ptr) = GC_ARRAY | ((IS_ARRAY_IMMUTABLE|GC_NOT_COLLECTABLE) << GC_FLAGS_SHIFT);
-       }
+       HashTable *ptr = zend_shared_memdup_put_free(attributes, sizeof(HashTable));
+       GC_SET_REFCOUNT(ptr, 2);
+       GC_TYPE_INFO(ptr) = GC_ARRAY | ((IS_ARRAY_IMMUTABLE|GC_NOT_COLLECTABLE) << GC_FLAGS_SHIFT);
 
        return ptr;
 }
@@ -450,7 +445,8 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc
                                }
                        }
                        if (op_array->attributes) {
-                               op_array->attributes = zend_persist_attributes(op_array->attributes);
+                               op_array->attributes = zend_shared_alloc_get_xlat_entry(op_array->attributes);
+                               ZEND_ASSERT(op_array->attributes != NULL);
                        }
 
                        if (op_array->try_catch_array) {