Skip to content

Commit f98e59c

Browse files
committed
Use single list for all flf arities
1 parent e1959a1 commit f98e59c

File tree

8 files changed

+51
-124
lines changed

8 files changed

+51
-124
lines changed

Zend/zend_API.c

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,39 +2956,21 @@ ZEND_API zend_result zend_register_functions(zend_class_entry *scope, const zend
29562956
if (reg_function->frameless_function_infos) {
29572957
const zend_frameless_function_info *flf_info = reg_function->frameless_function_infos;
29582958
while (flf_info->handler) {
2959-
void ***handler_list;
2960-
zend_function ***function_list;
2961-
size_t *count, *capacity;
2962-
#define GET_FLF_REFS(num_args) \
2963-
case num_args: \
2964-
handler_list = (void ***) &zend_frameless_function_## num_args ##_handlers; \
2965-
function_list = &zend_frameless_function_## num_args ##_functions; \
2966-
count = &zend_frameless_function_## num_args ##_count; \
2967-
capacity = &zend_frameless_function_## num_args ##_capacity; \
2968-
break;
2969-
switch (flf_info->num_args) {
2970-
GET_FLF_REFS(0);
2971-
GET_FLF_REFS(1);
2972-
GET_FLF_REFS(2);
2973-
GET_FLF_REFS(3);
2974-
EMPTY_SWITCH_DEFAULT_CASE();
2975-
}
2976-
#undef GET_FLF_REFS
2977-
if (*count == *capacity) {
2978-
if (!*capacity) {
2979-
*capacity = 8;
2959+
if (zend_flf_count == zend_flf_capacity) {
2960+
if (!zend_flf_capacity) {
2961+
zend_flf_capacity = 8;
29802962
} else {
2981-
*capacity *= 2;
2963+
zend_flf_capacity *= 2;
29822964
}
29832965
/* +1 for NULL terminator */
2984-
*handler_list = realloc(*handler_list, (*capacity + 1) * sizeof(void *));
2985-
*function_list = realloc(*function_list, (*capacity + 1) * sizeof(zend_function *));
2966+
zend_flf_handlers = realloc(zend_flf_handlers, (zend_flf_capacity + 1) * sizeof(void *));
2967+
zend_flf_functions = realloc(zend_flf_functions, (zend_flf_capacity + 1) * sizeof(zend_function *));
29862968
}
2987-
(*handler_list)[*count] = flf_info->handler;
2988-
(*function_list)[*count] = (zend_function *)reg_function;
2989-
(*count)++;
2990-
(*handler_list)[*count] = NULL;
2991-
(*function_list)[*count] = NULL;
2969+
zend_flf_handlers[zend_flf_count] = flf_info->handler;
2970+
zend_flf_functions[zend_flf_count] = (zend_function *)reg_function;
2971+
zend_flf_count++;
2972+
zend_flf_handlers[zend_flf_count] = NULL;
2973+
zend_flf_functions[zend_flf_count] = NULL;
29922974
flf_info++;
29932975
}
29942976
}

Zend/zend_compile.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4519,23 +4519,7 @@ static zend_result zend_compile_func_array_slice(znode *result, zend_ast_list *a
45194519

45204520
static int find_frameless_function_offset(int arity, void *handler)
45214521
{
4522-
void **handlers;
4523-
switch (arity) {
4524-
case 0:
4525-
handlers = (void **)zend_frameless_function_0_handlers;
4526-
break;
4527-
case 1:
4528-
handlers = (void **)zend_frameless_function_1_handlers;
4529-
break;
4530-
case 2:
4531-
handlers = (void **)zend_frameless_function_2_handlers;
4532-
break;
4533-
case 3:
4534-
handlers = (void **)zend_frameless_function_3_handlers;
4535-
break;
4536-
EMPTY_SWITCH_DEFAULT_CASE();
4537-
}
4538-
4522+
void **handlers = zend_flf_handlers;
45394523
void **current = handlers;
45404524
while (current) {
45414525
if (*current == handler) {

Zend/zend_frameless_function.c

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,7 @@
1818

1919
#include <stddef.h>
2020

21-
size_t zend_frameless_function_0_count = 0;
22-
size_t zend_frameless_function_1_count = 0;
23-
size_t zend_frameless_function_2_count = 0;
24-
size_t zend_frameless_function_3_count = 0;
25-
26-
size_t zend_frameless_function_0_capacity = 0;
27-
size_t zend_frameless_function_1_capacity = 0;
28-
size_t zend_frameless_function_2_capacity = 0;
29-
size_t zend_frameless_function_3_capacity = 0;
30-
31-
zend_frameless_function_0 *zend_frameless_function_0_handlers = NULL;
32-
zend_frameless_function_1 *zend_frameless_function_1_handlers = NULL;
33-
zend_frameless_function_2 *zend_frameless_function_2_handlers = NULL;
34-
zend_frameless_function_3 *zend_frameless_function_3_handlers = NULL;
35-
36-
zend_function **zend_frameless_function_0_functions = NULL;
37-
zend_function **zend_frameless_function_1_functions = NULL;
38-
zend_function **zend_frameless_function_2_functions = NULL;
39-
zend_function **zend_frameless_function_3_functions = NULL;
40-
41-
zend_function ** const* zend_frameless_function_functions_lists[] = {
42-
&zend_frameless_function_0_functions,
43-
&zend_frameless_function_1_functions,
44-
&zend_frameless_function_2_functions,
45-
&zend_frameless_function_3_functions,
46-
};
21+
size_t zend_flf_count = 0;
22+
size_t zend_flf_capacity = 0;
23+
void **zend_flf_handlers = NULL;
24+
zend_function **zend_flf_functions = NULL;

Zend/zend_frameless_function.h

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#define ZEND_FRAMELESS_FUNCTION_NAME(name, arity) zdc_##name##_##arity
2929
#define ZEND_OP_IS_FRAMELESS_ICALL(opcode) ((opcode) >= ZEND_FRAMELESS_ICALL_0 && (opcode) <= ZEND_FRAMELESS_ICALL_3)
3030
#define ZEND_FLF_NUM_ARGS(opcode) ((opcode) - ZEND_FRAMELESS_ICALL_0)
31-
#define ZEND_FLF_FUNC(opline) ((*zend_frameless_function_functions_lists[ZEND_FLF_NUM_ARGS((opline)->opcode)])[(opline)->extended_value])
31+
#define ZEND_FLF_FUNC(opline) (zend_flf_functions[(opline)->extended_value])
3232

3333
#define ZEND_FRAMELESS_FUNCTION(name, arity) \
3434
void ZEND_FRAMELESS_FUNCTION_NAME(name, arity)(DIRECT_FUNCTION_PARAMETERS_##arity)
@@ -72,34 +72,17 @@
7272
}
7373

7474
typedef struct _zval_struct zval;
75+
typedef union _zend_function zend_function;
7576

7677
typedef void (*zend_frameless_function_0)(zval *return_value);
7778
typedef void (*zend_frameless_function_1)(zval *return_value, zval *op1);
7879
typedef void (*zend_frameless_function_2)(zval *return_value, zval *op1, zval *op2);
7980
typedef void (*zend_frameless_function_3)(zval *return_value, zval *op1, zval *op2, zval *op3);
8081

81-
extern size_t zend_frameless_function_0_count;
82-
extern size_t zend_frameless_function_1_count;
83-
extern size_t zend_frameless_function_2_count;
84-
extern size_t zend_frameless_function_3_count;
85-
86-
extern size_t zend_frameless_function_0_capacity;
87-
extern size_t zend_frameless_function_1_capacity;
88-
extern size_t zend_frameless_function_2_capacity;
89-
extern size_t zend_frameless_function_3_capacity;
90-
91-
extern zend_frameless_function_0 *zend_frameless_function_0_handlers;
92-
extern zend_frameless_function_1 *zend_frameless_function_1_handlers;
93-
extern zend_frameless_function_2 *zend_frameless_function_2_handlers;
94-
extern zend_frameless_function_3 *zend_frameless_function_3_handlers;
95-
96-
typedef union _zend_function zend_function;
97-
98-
extern zend_function **zend_frameless_function_0_functions;
99-
extern zend_function **zend_frameless_function_1_functions;
100-
extern zend_function **zend_frameless_function_2_functions;
101-
extern zend_function **zend_frameless_function_3_functions;
102-
extern zend_function ** const* zend_frameless_function_functions_lists[];
82+
extern size_t zend_flf_count;
83+
extern size_t zend_flf_capacity;
84+
extern void **zend_flf_handlers;
85+
extern zend_function **zend_flf_functions;
10386

10487
typedef struct {
10588
void *handler;

Zend/zend_vm_def.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9548,7 +9548,7 @@ ZEND_VM_HANDLER(204, ZEND_FRAMELESS_ICALL_0, UNUSED, UNUSED)
95489548
{
95499549
USE_OPLINE
95509550
SAVE_OPLINE();
9551-
zend_frameless_function_0 function = zend_frameless_function_0_handlers[opline->extended_value];
9551+
zend_frameless_function_0 function = (zend_frameless_function_0)zend_flf_handlers[opline->extended_value];
95529552
function(EX_VAR(opline->result.var));
95539553
if (EG(exception)) {
95549554
ZVAL_NULL(EX_VAR(opline->result.var));
@@ -9561,7 +9561,7 @@ ZEND_VM_HANDLER(205, ZEND_FRAMELESS_ICALL_1, CONST|TMP|VAR|CV, UNUSED)
95619561
{
95629562
USE_OPLINE
95639563
SAVE_OPLINE();
9564-
zend_frameless_function_1 function = zend_frameless_function_1_handlers[opline->extended_value];
9564+
zend_frameless_function_1 function = (zend_frameless_function_1)zend_flf_handlers[opline->extended_value];
95659565
function(EX_VAR(opline->result.var), GET_OP1_ZVAL_PTR_DEREF(BP_VAR_R));
95669566
FREE_OP1();
95679567
if (EG(exception)) {
@@ -9575,7 +9575,7 @@ ZEND_VM_HANDLER(206, ZEND_FRAMELESS_ICALL_2, CONST|TMP|VAR|CV, CONST|TMP|VAR|CV)
95759575
{
95769576
USE_OPLINE
95779577
SAVE_OPLINE();
9578-
zend_frameless_function_2 function = zend_frameless_function_2_handlers[opline->extended_value];
9578+
zend_frameless_function_2 function = (zend_frameless_function_2)zend_flf_handlers[opline->extended_value];
95799579
function(
95809580
EX_VAR(opline->result.var),
95819581
GET_OP1_ZVAL_PTR_DEREF(BP_VAR_R),
@@ -9589,11 +9589,11 @@ ZEND_VM_HANDLER(206, ZEND_FRAMELESS_ICALL_2, CONST|TMP|VAR|CV, CONST|TMP|VAR|CV)
95899589
ZEND_VM_NEXT_OPCODE();
95909590
}
95919591

9592-
ZEND_VM_HANDLER(207, ZEND_FRAMELESS_ICALL_3, ANY, ANY, OP)
9592+
ZEND_VM_HANDLER(207, ZEND_FRAMELESS_ICALL_3, ANY, ANY)
95939593
{
95949594
USE_OPLINE
95959595
SAVE_OPLINE();
9596-
zend_frameless_function_3 function = zend_frameless_function_3_handlers[opline->extended_value];
9596+
zend_frameless_function_3 function = (zend_frameless_function_3)zend_flf_handlers[opline->extended_value];
95979597
function(
95989598
EX_VAR(opline->result.var),
95999599
GET_OP1_ZVAL_PTR_DEREF(BP_VAR_R),

Zend/zend_vm_execute.h

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)