Skip to content

Commit 86f81ca

Browse files
committed
Add support for empty immutable shared arrays
Why: - Since PHP 7.3, it's possible for extensions to create zvals backed by an immutable shared hashtable via the ZVAL_EMPTY_ARRAY macro. - This helps avoid redundant hashtable allocations when returning empty arrays back to userland PHP code, and could likewise be beneficial for Rust extensions too. What: - Add ZendHashTable::new_empty_immutable() to obtain a ZendHashTable that is actually an empty immutable shared hashtable. - Add ZendHashTable::is_immutable(). Use it to avoid attempting to free the immutable shared hashtable on drop, and to set appropriate type flags when initializing a zval with a ZendHashTable. - Make ZendHashTable's TryFrom implementations from Vec and HashMap return an empty immutable shared hashtable if the input collection was empty. Although this would allow every user to automatically benefit from this optimization, I'm not convinced about this part because this is technically a breaking change for consumers that construct ZendHashTables via these converters in their Rust code. Maybe it'd be better to not change the converters and let projects explicitly use ::new_empty_immutable if they deem the optimization would be useful.
1 parent 464407b commit 86f81ca

File tree

7 files changed

+214
-107
lines changed

7 files changed

+214
-107
lines changed

allowed_bindings.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ bind! {
8181
zend_declare_class_constant,
8282
zend_declare_property,
8383
zend_do_implement_interface,
84+
zend_empty_array,
8485
zend_execute_data,
8586
zend_function_entry,
8687
zend_hash_clean,
@@ -137,6 +138,9 @@ bind! {
137138
E_RECOVERABLE_ERROR,
138139
E_DEPRECATED,
139140
E_USER_DEPRECATED,
141+
GC_IMMUTABLE,
142+
GC_FLAGS_MASK,
143+
GC_FLAGS_SHIFT,
140144
HT_MIN_SIZE,
141145
IS_ARRAY,
142146
IS_ARRAY_EX,

0 commit comments

Comments
 (0)