1<?php
2$size = 4;
3$array = array();
4for ($key = 0, $maxKey = ($size - 1) * $size; $key <= $maxKey; $key +=$size) {
5 $array[$key] = 0;
6 }
通過打印p *execute_data->opline->handler可以獲得
ZEND_INIT_ARRAY_SPEC_UNUSED_UNUSED_HANDLER
//初始化數組
ZEND_ASSIGN_DIM_SPEC_CV_CV_HANDLER
zend_fetch_dimension_address
zend_fetch_dimension_address_inner
if(zend_hash_index_find(ht, index, (void **) &retval) == FAILURE) {
zend_hash_index_update(ht,index, &new_zval, sizeof(zval *), (void **) &retval);
}
zend_hash_index_update最終走的是
_zend_hash_index_update_or_next_insert
去掉插入之前的zend_hash_index_find
插入 65536 個惡意的元素需要 29.089669942856 秒
插入 65536 個普通元素需要 0.018018960952759 秒
執行以後發現僅降低了一般,還有29秒
另外的時間耽擱在了
在插入之前還有一次hash查找進行update的過程,並把指針指向當前index的鏈表結尾
_zend_hash_index_update_or_next_insert 函數裏面
問題
插入array的時候兩次調用了hash查找是否重複了,zend_fetch_dimension_address_inner裏面zend_hash_index_find有沒有必要?(存在查找到key值就不再進行插入的情況?)
參考 http://www.laruence.com/2011/12/30/2435.html