Skip to content

Commit a7aa4b3

Browse files
committed
Adjust static inline functions which don't inline
These are found by adding `-Winline` on gcc. The flag is accepted on clang for compatibility with gcc, but it doesn't do anything. Mostly, this removes `inline` from the declarations. For local static functions, there is no point in adding `inline`. This stems from either a misunderstanding of what it means, or alternatively is a holdover from ancient times where it may have meant something. A compiler is free to inline a static function, and specifying inline doesn't make the compiler inline the function. It does however make it harder to due analysis of failed inlining, so I remove them. However, for select functions, this changes them `zend_always_inline` instead. This is because these functions didn't inline, but probably should for performance reasons. For instance, `_class_exists_impl` is used in multiple frameless function handlers. I think in these cases, the authors were _hoping_ they'd be inlined due to fact that are important for performance. There's also `_php_search_array`, which is used with constant args on a variety of functions. It fails to inline due its size, but if it _did_ inline, it would cut large amounts of code out, so forcing the inlining seemed worth it.
1 parent f1b7335 commit a7aa4b3

23 files changed

+62
-68
lines changed

Zend/zend_ast.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@
2929

3030
ZEND_API zend_ast_process_t zend_ast_process = NULL;
3131

32-
static inline void *zend_ast_alloc(size_t size) {
32+
static void *zend_ast_alloc(size_t size) {
3333
return zend_arena_alloc(&CG(ast_arena), size);
3434
}
3535

36-
static inline void *zend_ast_realloc(void *old, size_t old_size, size_t new_size) {
36+
static void *zend_ast_realloc(void *old, size_t old_size, size_t new_size) {
3737
void *new = zend_ast_alloc(new_size);
3838
memcpy(new, old, old_size);
3939
return new;
4040
}
4141

42-
static inline size_t zend_ast_list_size(uint32_t children) {
42+
static size_t zend_ast_list_size(uint32_t children) {
4343
return sizeof(zend_ast_list) - sizeof(zend_ast *) + sizeof(zend_ast *) * children;
4444
}
4545

@@ -494,7 +494,7 @@ zend_ast *zend_ast_create_concat_op(zend_ast *op0, zend_ast *op1) {
494494
return zend_ast_create_binary_op(ZEND_CONCAT, op0, op1);
495495
}
496496

497-
static inline bool is_power_of_two(uint32_t n) {
497+
static zend_always_inline bool is_power_of_two(uint32_t n) {
498498
return ((n != 0) && (n == (n & (~n + 1))));
499499
}
500500

Zend/zend_builtin_functions.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ flf_clean:;
10531053
Z_FLF_PARAM_FREE_STR(2, property_tmp)
10541054
}
10551055

1056-
static inline void _class_exists_impl(zval *return_value, zend_string *name, bool autoload, int flags, int skip_flags) /* {{{ */
1056+
static zend_always_inline void _class_exists_impl(zval *return_value, zend_string *name, bool autoload, int flags, int skip_flags) /* {{{ */
10571057
{
10581058
zend_string *lcname;
10591059
zend_class_entry *ce;
@@ -1088,7 +1088,7 @@ static inline void _class_exists_impl(zval *return_value, zend_string *name, boo
10881088
}
10891089
/* {{{ */
10901090

1091-
static inline void class_exists_impl(INTERNAL_FUNCTION_PARAMETERS, int flags, int skip_flags) /* {{{ */
1091+
static void class_exists_impl(INTERNAL_FUNCTION_PARAMETERS, int flags, int skip_flags) /* {{{ */
10921092
{
10931093
zend_string *name;
10941094
bool autoload = true;
@@ -1386,7 +1386,7 @@ ZEND_FUNCTION(get_exception_handler)
13861386
}
13871387
}
13881388

1389-
static inline void get_declared_class_impl(INTERNAL_FUNCTION_PARAMETERS, int flags) /* {{{ */
1389+
static void get_declared_class_impl(INTERNAL_FUNCTION_PARAMETERS, int flags) /* {{{ */
13901390
{
13911391
zend_string *key;
13921392
zval *zv;

Zend/zend_exceptions.c

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,9 @@ static int zend_implement_throwable(zend_class_entry *interface, zend_class_entr
8181
}
8282
/* }}} */
8383

84-
static inline zend_class_entry *i_get_exception_base(zend_object *object) /* {{{ */
85-
{
86-
return instanceof_function(object->ce, zend_ce_exception) ? zend_ce_exception : zend_ce_error;
87-
}
88-
/* }}} */
89-
9084
ZEND_API zend_class_entry *zend_get_exception_base(zend_object *object) /* {{{ */
9185
{
92-
return i_get_exception_base(object);
86+
return instanceof_function(object->ce, zend_ce_exception) ? zend_ce_exception : zend_ce_error;
9387
}
9488
/* }}} */
9589

@@ -115,17 +109,17 @@ void zend_exception_set_previous(zend_object *exception, zend_object *add_previo
115109
ZVAL_OBJ(&zv, exception);
116110
ex = &zv;
117111
do {
118-
ancestor = zend_read_property_ex(i_get_exception_base(add_previous), add_previous, ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv);
112+
ancestor = zend_read_property_ex(zend_get_exception_base(add_previous), add_previous, ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv);
119113
ZVAL_DEREF(ancestor);
120114
while (Z_TYPE_P(ancestor) == IS_OBJECT) {
121115
if (Z_OBJ_P(ancestor) == Z_OBJ_P(ex)) {
122116
OBJ_RELEASE(add_previous);
123117
return;
124118
}
125-
ancestor = zend_read_property_ex(i_get_exception_base(Z_OBJ_P(ancestor)), Z_OBJ_P(ancestor), ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv);
119+
ancestor = zend_read_property_ex(zend_get_exception_base(Z_OBJ_P(ancestor)), Z_OBJ_P(ancestor), ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv);
126120
ZVAL_DEREF(ancestor);
127121
}
128-
base_ce = i_get_exception_base(Z_OBJ_P(ex));
122+
base_ce = zend_get_exception_base(Z_OBJ_P(ex));
129123
previous = zend_read_property_ex(base_ce, Z_OBJ_P(ex), ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv);
130124
ZVAL_DEREF(previous);
131125
if (Z_TYPE_P(previous) == IS_NULL) {
@@ -273,7 +267,7 @@ static zend_object *zend_default_exception_new(zend_class_entry *class_type) /*
273267
}
274268
Z_SET_REFCOUNT(trace, 0);
275269

276-
base_ce = i_get_exception_base(object);
270+
base_ce = zend_get_exception_base(object);
277271

278272
if (EXPECTED((class_type != zend_ce_parse_error && class_type != zend_ce_compile_error)
279273
|| !(filename = zend_get_compiled_filename()))) {
@@ -311,7 +305,7 @@ ZEND_METHOD(Exception, __construct)
311305
zend_class_entry *base_ce;
312306

313307
object = ZEND_THIS;
314-
base_ce = i_get_exception_base(Z_OBJ_P(object));
308+
base_ce = zend_get_exception_base(Z_OBJ_P(object));
315309

316310
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|SlO!", &message, &code, &previous, zend_ce_throwable) == FAILURE) {
317311
RETURN_THROWS();
@@ -335,9 +329,9 @@ ZEND_METHOD(Exception, __construct)
335329

336330
/* {{{ Exception unserialize checks */
337331
#define CHECK_EXC_TYPE(id, type) \
338-
pvalue = zend_read_property_ex(i_get_exception_base(Z_OBJ_P(object)), Z_OBJ_P(object), ZSTR_KNOWN(id), 1, &value); \
332+
pvalue = zend_read_property_ex(zend_get_exception_base(Z_OBJ_P(object)), Z_OBJ_P(object), ZSTR_KNOWN(id), 1, &value); \
339333
if (Z_TYPE_P(pvalue) != IS_NULL && Z_TYPE_P(pvalue) != type) { \
340-
zend_unset_property(i_get_exception_base(Z_OBJ_P(object)), Z_OBJ_P(object), ZSTR_VAL(ZSTR_KNOWN(id)), ZSTR_LEN(ZSTR_KNOWN(id))); \
334+
zend_unset_property(zend_get_exception_base(Z_OBJ_P(object)), Z_OBJ_P(object), ZSTR_VAL(ZSTR_KNOWN(id)), ZSTR_LEN(ZSTR_KNOWN(id))); \
341335
}
342336

343337
ZEND_METHOD(Exception, __wakeup)
@@ -401,9 +395,9 @@ ZEND_METHOD(ErrorException, __construct)
401395
/* }}} */
402396

403397
#define GET_PROPERTY(object, id) \
404-
zend_read_property_ex(i_get_exception_base(Z_OBJ_P(object)), Z_OBJ_P(object), ZSTR_KNOWN(id), 0, &rv)
398+
zend_read_property_ex(zend_get_exception_base(Z_OBJ_P(object)), Z_OBJ_P(object), ZSTR_KNOWN(id), 0, &rv)
405399
#define GET_PROPERTY_SILENT(object, id) \
406-
zend_read_property_ex(i_get_exception_base(Z_OBJ_P(object)), Z_OBJ_P(object), ZSTR_KNOWN(id), 1, &rv)
400+
zend_read_property_ex(zend_get_exception_base(Z_OBJ_P(object)), Z_OBJ_P(object), ZSTR_KNOWN(id), 1, &rv)
407401

408402
/* {{{ Get the file in which the exception occurred */
409403
ZEND_METHOD(Exception, getFile)
@@ -621,7 +615,7 @@ ZEND_METHOD(Exception, getTraceAsString)
621615
ZEND_PARSE_PARAMETERS_NONE();
622616

623617
zval *object = ZEND_THIS;
624-
zend_class_entry *base_ce = i_get_exception_base(Z_OBJ_P(object));
618+
zend_class_entry *base_ce = zend_get_exception_base(Z_OBJ_P(object));
625619
zval rv;
626620
const zval *trace = zend_read_property_ex(base_ce, Z_OBJ_P(object), ZSTR_KNOWN(ZEND_STR_TRACE), 1, &rv);
627621
if (EG(exception)) {
@@ -725,7 +719,7 @@ ZEND_METHOD(Exception, __toString)
725719

726720
exception = ZEND_THIS;
727721
/* Reset apply counts */
728-
while (Z_TYPE_P(exception) == IS_OBJECT && (base_ce = i_get_exception_base(Z_OBJ_P(exception))) && instanceof_function(Z_OBJCE_P(exception), base_ce)) {
722+
while (Z_TYPE_P(exception) == IS_OBJECT && (base_ce = zend_get_exception_base(Z_OBJ_P(exception))) && instanceof_function(Z_OBJCE_P(exception), base_ce)) {
729723
if (Z_IS_RECURSIVE_P(exception)) {
730724
Z_UNPROTECT_RECURSION_P(exception);
731725
} else {
@@ -736,7 +730,7 @@ ZEND_METHOD(Exception, __toString)
736730
}
737731

738732
exception = ZEND_THIS;
739-
base_ce = i_get_exception_base(Z_OBJ_P(exception));
733+
base_ce = zend_get_exception_base(Z_OBJ_P(exception));
740734

741735
/* We store the result in the private property string so we can access
742736
* the result in uncaught exception handlers without memleaks. */
@@ -928,7 +922,7 @@ ZEND_API ZEND_COLD zend_result zend_exception_error(zend_object *ex, int severit
928922
if (Z_TYPE(tmp) != IS_STRING) {
929923
zend_error(E_WARNING, "%s::__toString() must return a string", ZSTR_VAL(ce_exception->name));
930924
} else {
931-
zend_update_property_ex(i_get_exception_base(ex), ex, ZSTR_KNOWN(ZEND_STR_STRING), &tmp);
925+
zend_update_property_ex(zend_get_exception_base(ex), ex, ZSTR_KNOWN(ZEND_STR_STRING), &tmp);
932926
}
933927
}
934928
zval_ptr_dtor(&tmp);

Zend/zend_generators.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static zend_always_inline void clear_link_to_root(zend_generator *generator) {
213213
}
214214

215215
/* Check if the node 'generator' is running in a fiber */
216-
static inline bool check_node_running_in_fiber(zend_generator *generator) {
216+
static bool check_node_running_in_fiber(zend_generator *generator) {
217217
ZEND_ASSERT(generator->execute_data);
218218

219219
if (EXPECTED(generator->flags & ZEND_GENERATOR_IN_FIBER)) {
@@ -872,7 +872,7 @@ ZEND_API void zend_generator_resume(zend_generator *orig_generator) /* {{{ */
872872
}
873873
/* }}} */
874874

875-
static inline void zend_generator_ensure_initialized(zend_generator *generator) /* {{{ */
875+
static void zend_generator_ensure_initialized(zend_generator *generator) /* {{{ */
876876
{
877877
if (UNEXPECTED(Z_TYPE(generator->value) == IS_UNDEF) && EXPECTED(generator->execute_data) && EXPECTED(generator->node.parent == NULL)) {
878878
zend_generator_resume(generator);
@@ -881,7 +881,7 @@ static inline void zend_generator_ensure_initialized(zend_generator *generator)
881881
}
882882
/* }}} */
883883

884-
static inline void zend_generator_rewind(zend_generator *generator) /* {{{ */
884+
static void zend_generator_rewind(zend_generator *generator) /* {{{ */
885885
{
886886
zend_generator_ensure_initialized(generator);
887887

ext/hash/hash_gost.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@
203203
AA(v, l, r); \
204204
}
205205

206-
static inline void Gost(PHP_GOST_CTX *context, uint32_t data[8])
206+
static void Gost(PHP_GOST_CTX *context, uint32_t data[8])
207207
{
208208
int i;
209209
uint32_t l, r, t, key[8], u[8], v[8], w[8], s[8], *h = context->state, *m = data;

ext/hash/hash_snefru.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void ph(uint32_t h[16])
3737
}
3838
#endif
3939

40-
static inline void Snefru(uint32_t input[16])
40+
static void Snefru(uint32_t input[16])
4141
{
4242
static const int shifts[4] = {16, 8, 16, 24};
4343
int b, index, rshift, lshift;

ext/hash/hash_tiger.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
}
133133
/* }}} */
134134

135-
static inline void TigerFinalize(PHP_TIGER_CTX *context)
135+
static void TigerFinalize(PHP_TIGER_CTX *context)
136136
{
137137
context->passed += (uint64_t) context->length << 3;
138138

ext/json/json_encoder.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ bool php_json_is_valid_double(double d) /* {{{ */
9090
}
9191
/* }}} */
9292

93-
static inline void php_json_encode_double(smart_str *buf, double d, int options) /* {{{ */
93+
static void php_json_encode_double(smart_str *buf, double d, int options) /* {{{ */
9494
{
9595
size_t len;
9696
char num[ZEND_DOUBLE_MAX_LENGTH];

ext/opcache/ZendAccelerator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static ZEND_FUNCTION(accel_chdir)
230230
ZCG(cwd_check) = true;
231231
}
232232

233-
static inline zend_string* accel_getcwd(void)
233+
static zend_string* accel_getcwd(void)
234234
{
235235
if (ZCG(cwd)) {
236236
return ZCG(cwd);

ext/random/engine_mt19937.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ ZEND_STATIC_ASSERT(
100100
#define twist(m,u,v) (m ^ (mixBits(u,v) >> 1) ^ ((uint32_t)(-(int32_t)(loBit(v))) & 0x9908b0dfU))
101101
#define twist_php(m,u,v) (m ^ (mixBits(u,v) >> 1) ^ ((uint32_t)(-(int32_t)(loBit(u))) & 0x9908b0dfU))
102102

103-
static inline void mt19937_reload(php_random_status_state_mt19937 *state)
103+
static void mt19937_reload(php_random_status_state_mt19937 *state)
104104
{
105105
uint32_t *p = state->state;
106106

0 commit comments

Comments
 (0)