]> granicus.if.org Git - php/commitdiff
- Increase performance of *sort() and some internal sort operations.
authorMarcus Boerger <helly@php.net>
Thu, 29 Jul 2004 19:18:46 +0000 (19:18 +0000)
committerMarcus Boerger <helly@php.net>
Thu, 29 Jul 2004 19:18:46 +0000 (19:18 +0000)
# This patch increases the performance of small arrays/hashes by up to ~15%
# The performance increase during the performance talk :-)

Zend/zend_hash.c

index 065c9b46805b4c16d45fe2d6eb8fed4cc91292b6..22754aba9b7ac455b5e1238f181e20a9ab396326 100644 (file)
@@ -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();