]> granicus.if.org Git - php/commitdiff
Fixed callback registraion order in spl_autoload_register()
authorDmitry Stogov <dmitry@zend.com>
Tue, 29 Jul 2014 12:23:56 +0000 (16:23 +0400)
committerDmitry Stogov <dmitry@zend.com>
Tue, 29 Jul 2014 12:23:56 +0000 (16:23 +0400)
ext/spl/php_spl.c

index d765d6b7545d63b30285ea89ffa5ef40a1c69312..62cf6ae14424a93fabd44b2833bafcd0309594c6 100644 (file)
@@ -441,24 +441,11 @@ PHP_FUNCTION(spl_autoload_call)
 
 #define HT_MOVE_TAIL_TO_HEAD(ht)                                                       \
        do {                                                                                                    \
-               uint first = 0;                                                                         \
-               uint last = (ht)->nNumUsed;                                                     \
-               while (first < last) {                                                          \
-                       if (Z_TYPE((ht)->arData[first].val) != IS_UNDEF)    \
-                               break;                                                  \
-                       first++;                                                                                \
-               }                                                                                                       \
-               while (last > first) {                                                          \
-                       last--;                                                                                 \
-                       if (Z_TYPE((ht)->arData[last].val) != IS_UNDEF)     \
-                               break;                                                  \
-               }                                                                                                       \
-               if (first != last) {                                                            \
-                       Bucket tmp = (ht)->arData[first];                   \
-                       (ht)->arData[first] = (ht)->arData[last];           \
-                       (ht)->arData[last] = tmp;                           \
-                       zend_hash_rehash(ht);                                                   \
-               }                                                                                                       \
+               Bucket tmp = (ht)->arData[(ht)->nNumUsed-1];                            \
+               memmove((ht)->arData + 1, (ht)->arData,                                 \
+                       sizeof(Bucket) * ((ht)->nNumUsed - 1));                         \
+               (ht)->arData[0] = tmp;                                                                  \
+               zend_hash_rehash(ht);                                                           \
        } while (0)
 
 /* {{{ proto bool spl_autoload_register([mixed autoload_function = "spl_autoload" [, throw = true [, prepend]]])