table = swTable_new(table_size, conflict_proportion); if (table == NULL) { zend_throw_exception(swoole_exception_ce, "global memory allocation failure", SW_ERROR_MALLOC_FAIL); RETURN_FALSE; } table->hash_func = [](const char key, size_t len) -> uint64_t { zend_string string = (zend_string ) (key - offsetof(zend_string, val)); return zend_string_hash_val(string); }; php_swoole_table_set_ptr(ZEND_THIS, table);
这里有一个主要的优化,底层利用了 zend_string_hash_val ,当 PHP 层传入的 KEY 已经打算过 Hash 值,就可以直接返回 zend_string->h ,不再须要进行 hash 打算。
这里利用了 PHP7 新的 HashTable 优化,可以节省很多不必要的 hash 函数调用。
这里

领取办法:点赞关注小编后私信【资料】获取资料领取办法!