Skip to content

Commit dfb9e03

Browse files
committed
Use Z_PARAM_OBJ macros when zval isn't needed
In some cases, like spl_object_id, the code is simpler but equally efficient after optimizations. In other cases, like get_mangled_object_vars(), the compiler can't infer that the object in the zval won't change. Closes GH-6567
1 parent 64c753e commit dfb9e03

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

Diff for: Zend/zend_builtin_functions.c

+6-8
Original file line numberDiff line numberDiff line change
@@ -769,18 +769,16 @@ ZEND_FUNCTION(get_class_vars)
769769
/* {{{ Returns an array of object properties */
770770
ZEND_FUNCTION(get_object_vars)
771771
{
772-
zval *obj;
773772
zval *value;
774773
HashTable *properties;
775774
zend_string *key;
776775
zend_object *zobj;
777776
zend_ulong num_key;
778777

779778
ZEND_PARSE_PARAMETERS_START(1, 1)
780-
Z_PARAM_OBJECT(obj)
779+
Z_PARAM_OBJ(zobj)
781780
ZEND_PARSE_PARAMETERS_END();
782781

783-
zobj = Z_OBJ_P(obj);
784782
properties = zobj->handlers->get_properties(zobj);
785783
if (properties == NULL) {
786784
RETURN_EMPTY_ARRAY();
@@ -839,22 +837,22 @@ ZEND_FUNCTION(get_object_vars)
839837
/* {{{ Returns an array of mangled object properties. Does not respect property visibility. */
840838
ZEND_FUNCTION(get_mangled_object_vars)
841839
{
842-
zval *obj;
840+
zend_object *obj;
843841
HashTable *properties;
844842

845843
ZEND_PARSE_PARAMETERS_START(1, 1)
846-
Z_PARAM_OBJECT(obj)
844+
Z_PARAM_OBJ(obj)
847845
ZEND_PARSE_PARAMETERS_END();
848846

849-
properties = Z_OBJ_HT_P(obj)->get_properties(Z_OBJ_P(obj));
847+
properties = obj->handlers->get_properties(obj);
850848
if (!properties) {
851849
ZVAL_EMPTY_ARRAY(return_value);
852850
return;
853851
}
854852

855853
properties = zend_proptable_to_symtable(properties,
856-
(Z_OBJCE_P(obj)->default_properties_count ||
857-
Z_OBJ_P(obj)->handlers != &std_object_handlers ||
854+
(obj->ce->default_properties_count ||
855+
obj->handlers != &std_object_handlers ||
858856
GC_IS_RECURSIVE(properties)));
859857
RETURN_ARR(properties);
860858
}

Diff for: Zend/zend_closures.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ ZEND_METHOD(Closure, call)
128128
zend_fcall_info_cache fci_cache;
129129
zend_function my_function;
130130
zend_object *newobj;
131+
zend_class_entry *newclass;
131132

132133
fci.param_count = 0;
133134
fci.params = NULL;
@@ -140,26 +141,27 @@ ZEND_METHOD(Closure, call)
140141
closure = (zend_closure *) Z_OBJ_P(ZEND_THIS);
141142

142143
newobj = Z_OBJ_P(newthis);
144+
newclass = newobj->ce;
143145

144-
if (!zend_valid_closure_binding(closure, newthis, Z_OBJCE_P(newthis))) {
146+
if (!zend_valid_closure_binding(closure, newthis, newclass)) {
145147
return;
146148
}
147149

148150
if (closure->func.common.fn_flags & ZEND_ACC_GENERATOR) {
149151
zval new_closure;
150-
zend_create_closure(&new_closure, &closure->func, Z_OBJCE_P(newthis), closure->called_scope, newthis);
152+
zend_create_closure(&new_closure, &closure->func, newclass, closure->called_scope, newthis);
151153
closure = (zend_closure *) Z_OBJ(new_closure);
152154
fci_cache.function_handler = &closure->func;
153155
} else {
154156
memcpy(&my_function, &closure->func, closure->func.type == ZEND_USER_FUNCTION ? sizeof(zend_op_array) : sizeof(zend_internal_function));
155157
my_function.common.fn_flags &= ~ZEND_ACC_CLOSURE;
156158
/* use scope of passed object */
157-
my_function.common.scope = Z_OBJCE_P(newthis);
159+
my_function.common.scope = newclass;
158160
fci_cache.function_handler = &my_function;
159161

160162
/* Runtime cache relies on bound scope to be immutable, hence we need a separate rt cache in case scope changed */
161163
if (ZEND_USER_CODE(my_function.type)
162-
&& (closure->func.common.scope != Z_OBJCE_P(newthis)
164+
&& (closure->func.common.scope != newclass
163165
|| (closure->func.common.fn_flags & ZEND_ACC_HEAP_RT_CACHE))) {
164166
void *ptr;
165167

@@ -172,7 +174,7 @@ ZEND_METHOD(Closure, call)
172174
}
173175
}
174176

175-
fci_cache.called_scope = newobj->ce;
177+
fci_cache.called_scope = newclass;
176178
fci_cache.object = fci.object = newobj;
177179

178180
fci.size = sizeof(fci);

Diff for: Zend/zend_weakrefs.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ static zend_object* zend_weakref_new(zend_class_entry *ce) {
181181
return &wr->std;
182182
}
183183

184-
static zend_always_inline zend_bool zend_weakref_find(zval *referent, zval *return_value) {
185-
void *tagged_ptr = zend_hash_index_find_ptr(&EG(weakrefs), (zend_ulong) Z_OBJ_P(referent));
184+
static zend_always_inline zend_bool zend_weakref_find(zend_object *referent, zval *return_value) {
185+
void *tagged_ptr = zend_hash_index_find_ptr(&EG(weakrefs), (zend_ulong) referent);
186186
if (!tagged_ptr) {
187187
return 0;
188188
}
@@ -209,13 +209,13 @@ static zend_always_inline zend_bool zend_weakref_find(zval *referent, zval *retu
209209
return 0;
210210
}
211211

212-
static zend_always_inline void zend_weakref_create(zval *referent, zval *return_value) {
212+
static zend_always_inline void zend_weakref_create(zend_object *referent, zval *return_value) {
213213
zend_weakref *wr;
214214

215215
object_init_ex(return_value, zend_ce_weakref);
216216

217217
wr = zend_weakref_fetch(return_value);
218-
wr->referent = Z_OBJ_P(referent);
218+
wr->referent = referent;
219219

220220
zend_weakref_register(wr->referent, ZEND_WEAKREF_ENCODE(wr, ZEND_WEAKREF_TAG_REF));
221221
}
@@ -245,10 +245,10 @@ ZEND_COLD ZEND_METHOD(WeakReference, __construct)
245245

246246
ZEND_METHOD(WeakReference, create)
247247
{
248-
zval *referent;
248+
zend_object *referent;
249249

250250
ZEND_PARSE_PARAMETERS_START(1,1)
251-
Z_PARAM_OBJECT(referent)
251+
Z_PARAM_OBJ(referent)
252252
ZEND_PARSE_PARAMETERS_END();
253253

254254
if (zend_weakref_find(referent, return_value)) {

Diff for: ext/spl/php_spl.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,13 @@ PHP_FUNCTION(spl_object_hash)
641641
/* {{{ Returns the integer object handle for the given object */
642642
PHP_FUNCTION(spl_object_id)
643643
{
644-
zval *obj;
644+
zend_object *obj;
645645

646646
ZEND_PARSE_PARAMETERS_START(1, 1)
647-
Z_PARAM_OBJECT(obj)
647+
Z_PARAM_OBJ(obj)
648648
ZEND_PARSE_PARAMETERS_END();
649649

650-
RETURN_LONG((zend_long)Z_OBJ_HANDLE_P(obj));
650+
RETURN_LONG((zend_long)obj->handle);
651651
}
652652
/* }}} */
653653

0 commit comments

Comments
 (0)