mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Add zend_object_alloc() API
Using ecalloc() to create objects is expensive, because the dynamic-size memset() is unreasonably slow. Make sure we only zero the main object structure with known size, as the properties are intialized separately anyway. Technically we do not need to zero the embedded zend_object structure either, but as long as the memset argument is constant, a couple more bytes don't really matter.
This commit is contained in:
@@ -86,6 +86,15 @@ static zend_always_inline size_t zend_object_properties_size(zend_class_entry *c
|
||||
((ce->ce_flags & ZEND_ACC_USE_GUARDS) ? 0 : 1));
|
||||
}
|
||||
|
||||
/* Allocates object type and zeros it, but not the properties.
|
||||
* Properties MUST be initialized using object_properties_init(). */
|
||||
static zend_always_inline void *zend_object_alloc(size_t obj_size, zend_class_entry *ce) {
|
||||
void *obj = emalloc(obj_size + zend_object_properties_size(ce));
|
||||
memset(obj, 0, obj_size);
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
#endif /* ZEND_OBJECTS_H */
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user