Skip to content

Commit 4862297

Browse files
committed
Extract functions for file cache type serialization
This is already done in master.
1 parent 36d5fbb commit 4862297

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

ext/opcache/zend_file_cache.c

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,21 @@ static void zend_file_cache_serialize_zval(zval *zv,
371371
}
372372
}
373373

374+
static void zend_file_cache_serialize_type(
375+
zend_type *type, zend_persistent_script *script, zend_file_cache_metainfo *info, void *buf)
376+
{
377+
if (ZEND_TYPE_IS_CLASS(*type)) {
378+
zend_bool allow_null = ZEND_TYPE_ALLOW_NULL(*type);
379+
zend_string *type_name = ZEND_TYPE_NAME(*type);
380+
381+
SERIALIZE_STR(type_name);
382+
*type =
383+
(Z_UL(1) << (sizeof(zend_type)*8-1)) | /* type is class */
384+
(allow_null ? (Z_UL(1) << (sizeof(zend_type)*8-2)) : Z_UL(0)) | /* type allow null */
385+
(zend_type)type_name;
386+
}
387+
}
388+
374389
static void zend_file_cache_serialize_op_array(zend_op_array *op_array,
375390
zend_persistent_script *script,
376391
zend_file_cache_metainfo *info,
@@ -498,16 +513,7 @@ static void zend_file_cache_serialize_op_array(zend_op_array *op_arra
498513
if (!IS_SERIALIZED(p->name)) {
499514
SERIALIZE_STR(p->name);
500515
}
501-
if (ZEND_TYPE_IS_CLASS(p->type)) {
502-
zend_bool allow_null = ZEND_TYPE_ALLOW_NULL(p->type);
503-
zend_string *type_name = ZEND_TYPE_NAME(p->type);
504-
505-
SERIALIZE_STR(type_name);
506-
p->type =
507-
(Z_UL(1) << (sizeof(zend_type)*8-1)) | /* type is class */
508-
(allow_null ? (Z_UL(1) << (sizeof(zend_type)*8-2)) : Z_UL(0)) | /* type allow null */
509-
(zend_type)type_name;
510-
}
516+
zend_file_cache_serialize_type(&p->type, script, info, buf);
511517
p++;
512518
}
513519
}
@@ -1080,6 +1086,18 @@ static void zend_file_cache_unserialize_zval(zval *zv,
10801086
}
10811087
}
10821088

1089+
static void zend_file_cache_unserialize_type(
1090+
zend_type *type, zend_persistent_script *script, void *buf)
1091+
{
1092+
if (*type & (Z_UL(1) << (sizeof(zend_type)*8-1))) { /* type is class */
1093+
zend_bool allow_null = (*type & (Z_UL(1) << (sizeof(zend_type)*8-2))) != 0; /* type allow null */
1094+
zend_string *type_name = (zend_string*)(*type & ~(((Z_UL(1) << (sizeof(zend_type)*8-1))) | ((Z_UL(1) << (sizeof(zend_type)*8-2)))));
1095+
1096+
UNSERIALIZE_STR(type_name);
1097+
*type = ZEND_TYPE_ENCODE_CLASS(type_name, allow_null);
1098+
}
1099+
}
1100+
10831101
static void zend_file_cache_unserialize_op_array(zend_op_array *op_array,
10841102
zend_persistent_script *script,
10851103
void *buf)
@@ -1195,13 +1213,7 @@ static void zend_file_cache_unserialize_op_array(zend_op_array *op_arr
11951213
if (!IS_UNSERIALIZED(p->name)) {
11961214
UNSERIALIZE_STR(p->name);
11971215
}
1198-
if (p->type & (Z_UL(1) << (sizeof(zend_type)*8-1))) { /* type is class */
1199-
zend_bool allow_null = (p->type & (Z_UL(1) << (sizeof(zend_type)*8-2))) != 0; /* type allow null */
1200-
zend_string *type_name = (zend_string*)(p->type & ~(((Z_UL(1) << (sizeof(zend_type)*8-1))) | ((Z_UL(1) << (sizeof(zend_type)*8-2)))));
1201-
1202-
UNSERIALIZE_STR(type_name);
1203-
p->type = ZEND_TYPE_ENCODE_CLASS(type_name, allow_null);
1204-
}
1216+
zend_file_cache_unserialize_type(&p->type, script, buf);
12051217
p++;
12061218
}
12071219
}

0 commit comments

Comments
 (0)