Skip to content

Commit 4cff8c1

Browse files
committed
Simplify attribute persistence
For an inherited op_array, directly fetch the xlat entry, as we do for everything else.
1 parent 69018da commit 4cff8c1

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

ext/opcache/zend_persist.c

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -259,40 +259,35 @@ static void zend_persist_zval(zval *z)
259259

260260
static HashTable *zend_persist_attributes(HashTable *attributes)
261261
{
262-
HashTable *ptr = zend_shared_alloc_get_xlat_entry(attributes);
263-
264-
if (!ptr) {
265-
uint32_t i;
266-
zval *v;
262+
uint32_t i;
263+
zval *v;
267264

268-
if (!ZCG(current_persistent_script)->corrupted
269-
&& zend_accel_in_shm(attributes)) {
270-
return attributes;
271-
}
265+
if (!ZCG(current_persistent_script)->corrupted && zend_accel_in_shm(attributes)) {
266+
return attributes;
267+
}
272268

273-
zend_hash_persist(attributes);
269+
zend_hash_persist(attributes);
274270

275-
ZEND_HASH_FOREACH_VAL(attributes, v) {
276-
zend_attribute *attr = Z_PTR_P(v);
277-
zend_attribute *copy = zend_shared_memdup_put_free(attr, ZEND_ATTRIBUTE_SIZE(attr->argc));
271+
ZEND_HASH_FOREACH_VAL(attributes, v) {
272+
zend_attribute *attr = Z_PTR_P(v);
273+
zend_attribute *copy = zend_shared_memdup_put_free(attr, ZEND_ATTRIBUTE_SIZE(attr->argc));
278274

279-
zend_accel_store_interned_string(copy->name);
280-
zend_accel_store_interned_string(copy->lcname);
275+
zend_accel_store_interned_string(copy->name);
276+
zend_accel_store_interned_string(copy->lcname);
281277

282-
for (i = 0; i < copy->argc; i++) {
283-
if (copy->args[i].name) {
284-
zend_accel_store_interned_string(copy->args[i].name);
285-
}
286-
zend_persist_zval(&copy->args[i].value);
278+
for (i = 0; i < copy->argc; i++) {
279+
if (copy->args[i].name) {
280+
zend_accel_store_interned_string(copy->args[i].name);
287281
}
282+
zend_persist_zval(&copy->args[i].value);
283+
}
288284

289-
ZVAL_PTR(v, copy);
290-
} ZEND_HASH_FOREACH_END();
285+
ZVAL_PTR(v, copy);
286+
} ZEND_HASH_FOREACH_END();
291287

292-
ptr = zend_shared_memdup_put_free(attributes, sizeof(HashTable));
293-
GC_SET_REFCOUNT(ptr, 2);
294-
GC_TYPE_INFO(ptr) = GC_ARRAY | ((IS_ARRAY_IMMUTABLE|GC_NOT_COLLECTABLE) << GC_FLAGS_SHIFT);
295-
}
288+
HashTable *ptr = zend_shared_memdup_put_free(attributes, sizeof(HashTable));
289+
GC_SET_REFCOUNT(ptr, 2);
290+
GC_TYPE_INFO(ptr) = GC_ARRAY | ((IS_ARRAY_IMMUTABLE|GC_NOT_COLLECTABLE) << GC_FLAGS_SHIFT);
296291

297292
return ptr;
298293
}
@@ -450,7 +445,8 @@ static void zend_persist_op_array_ex(zend_op_array *op_array, zend_persistent_sc
450445
}
451446
}
452447
if (op_array->attributes) {
453-
op_array->attributes = zend_persist_attributes(op_array->attributes);
448+
op_array->attributes = zend_shared_alloc_get_xlat_entry(op_array->attributes);
449+
ZEND_ASSERT(op_array->attributes != NULL);
454450
}
455451

456452
if (op_array->try_catch_array) {

0 commit comments

Comments
 (0)