Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -9719,7 +9719,11 @@ ZEND_VM_HANDLER(202, ZEND_CALLABLE_CONVERT, UNUSED, UNUSED, NUM|CACHE_SLOT)
if (closure) {
ZVAL_OBJ_COPY(EX_VAR(opline->result.var), closure);
} else {
zval *closure_zv = zend_hash_index_lookup(&EG(callable_convert_cache), (zend_ulong)(uintptr_t)call->func);
/* Rotate the key for better hash distribution. */
const int shift = sizeof(size_t) == 4 ? 6 : 7;
zend_ulong key = (zend_ulong)(uintptr_t)call->func;
key = (key >> shift) | (key << ((sizeof(key) * 8) - shift));
zval *closure_zv = zend_hash_index_lookup(&EG(callable_convert_cache), key);
Comment on lines -9722 to +9726
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rotated address is not significantly better. It's better to choose one of the well known hash function for integers e.g. from https://arxiv.org/pdf/1504.06804

if (Z_TYPE_P(closure_zv) == IS_NULL) {
zend_closure_from_frame(closure_zv, call);
}
Expand Down
12 changes: 10 additions & 2 deletions Zend/zend_vm_execute.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.