summaryrefslogtreecommitdiff
path: root/Zend/zend_objects_API.h
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2017-11-25 16:07:51 +0100
committerNikita Popov <nikita.ppv@gmail.com>2017-11-25 17:12:37 +0100
commitb72b1a4e4d4a94a16b953bf8d826885efb56eeca (patch)
treed79e5390c77d3a5218f39262f2205280dacb8bf7 /Zend/zend_objects_API.h
parent8795893f4f90a344cc9a9d48523b7aa0ba5ebf05 (diff)
downloadphp-git-b72b1a4e4d4a94a16b953bf8d826885efb56eeca.tar.gz
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.
Diffstat (limited to 'Zend/zend_objects_API.h')
-rw-r--r--Zend/zend_objects_API.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/Zend/zend_objects_API.h b/Zend/zend_objects_API.h
index c21d1a3b0a..cffd9ee273 100644
--- a/Zend/zend_objects_API.h
+++ b/Zend/zend_objects_API.h
@@ -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 */
/*