diff options
author | Marcus Boerger <helly@php.net> | 2004-07-29 19:18:46 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2004-07-29 19:18:46 +0000 |
commit | dcf007c6da55ed91a96d45442e9d071ed975084e (patch) | |
tree | 03f1fd3b90636bc759e57d9b04203acee32384d2 | |
parent | d96e7a170ce77daea8bb1fd69658b57a28e301e3 (diff) | |
download | php-git-dcf007c6da55ed91a96d45442e9d071ed975084e.tar.gz |
- Increase performance of *sort() and some internal sort operations.
# This patch increases the performance of small arrays/hashes by up to ~15%
# The performance increase during the performance talk :-)
-rw-r--r-- | Zend/zend_hash.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index 065c9b4680..22754aba9b 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -1138,14 +1138,20 @@ ZEND_API int zend_hash_sort(HashTable *ht, sort_func_t sort_func, ht->pListTail = NULL; ht->pInternalPointer = ht->pListHead; - for (j = 0; j < i; j++) { - if (ht->pListTail) { - ht->pListTail->pListNext = arTmp[j]; - } - arTmp[j]->pListLast = ht->pListTail; - arTmp[j]->pListNext = NULL; - ht->pListTail = arTmp[j]; - } + arTmp[0]->pListLast = NULL; + if (i > 1) { + arTmp[0]->pListNext = arTmp[1]; + for (j = 1; j < i-1; j++) { + arTmp[j]->pListLast = arTmp[j-1]; + arTmp[j]->pListNext = arTmp[j+1]; + } + arTmp[j]->pListLast = ht->pListTail; + arTmp[j]->pListNext = NULL; + } else { + arTmp[0]->pListNext = NULL; + } + ht->pListTail = arTmp[i-1]; + pefree(arTmp, ht->persistent); HANDLE_UNBLOCK_INTERRUPTIONS(); |