]> granicus.if.org Git - php/commitdiff
Remove unnecessary NULL checks from zend_hash
authorNikita Popov <nikic@php.net>
Mon, 17 Jun 2013 16:51:59 +0000 (18:51 +0200)
committerNikita Popov <nikic@php.net>
Mon, 17 Jun 2013 16:51:59 +0000 (18:51 +0200)
Our memory allocation functions (including the persistent ones)
are infallible, so no need to check for NULL.

Zend/zend_hash.c

index 27b603eed2d3bc3825de239998dd1b37b7550489..1369242755962654e695b2d5754a704a2b453766 100644 (file)
@@ -96,7 +96,7 @@ static void _zend_is_inconsistent(const HashTable *ht, const char *file, int lin
                zend_hash_do_resize(ht);                                        \
        }
 
-static int zend_hash_do_resize(HashTable *ht);
+static void zend_hash_do_resize(HashTable *ht);
 
 ZEND_API ulong zend_hash_func(const char *arKey, uint nKeyLength)
 {
@@ -128,10 +128,6 @@ ZEND_API ulong zend_hash_func(const char *arKey, uint nKeyLength)
                (p)->pData = &(p)->pDataPtr;                                                                    \
        } else {                                                                                                                        \
                (p)->pData = (void *) pemalloc_rel(nDataSize, (ht)->persistent);\
-               if (!(p)->pData) {                                                                                              \
-                       pefree_rel(p, (ht)->persistent);                                                        \
-                       return FAILURE;                                                                                         \
-               }                                                                                                                               \
                memcpy((p)->pData, pData, nDataSize);                                                   \
                (p)->pDataPtr=NULL;                                                                                             \
        }
@@ -245,15 +241,9 @@ ZEND_API int _zend_hash_add_or_update(HashTable *ht, const char *arKey, uint nKe
        
        if (IS_INTERNED(arKey)) {
                p = (Bucket *) pemalloc(sizeof(Bucket), ht->persistent);
-               if (!p) {
-                       return FAILURE;
-               }
                p->arKey = arKey;
        } else {
                p = (Bucket *) pemalloc(sizeof(Bucket) + nKeyLength, ht->persistent);
-               if (!p) {
-                       return FAILURE;
-               }
                p->arKey = (const char*)(p + 1);
                memcpy((char*)p->arKey, arKey, nKeyLength);
        }
@@ -322,15 +312,9 @@ ZEND_API int _zend_hash_quick_add_or_update(HashTable *ht, const char *arKey, ui
        
        if (IS_INTERNED(arKey)) {
                p = (Bucket *) pemalloc(sizeof(Bucket), ht->persistent);
-               if (!p) {
-                       return FAILURE;
-               }
                p->arKey = arKey;
        } else {
                p = (Bucket *) pemalloc(sizeof(Bucket) + nKeyLength, ht->persistent);
-               if (!p) {
-                       return FAILURE;
-               }
                p->arKey = (const char*)(p + 1);
                memcpy((char*)p->arKey, arKey, nKeyLength);
        }
@@ -410,9 +394,6 @@ ZEND_API int _zend_hash_index_update_or_next_insert(HashTable *ht, ulong h, void
                p = p->pNext;
        }
        p = (Bucket *) pemalloc_rel(sizeof(Bucket), ht->persistent);
-       if (!p) {
-               return FAILURE;
-       }
        p->arKey = NULL;
        p->nKeyLength = 0; /* Numeric indices are marked by making the nKeyLength == 0 */
        p->h = h;
@@ -437,7 +418,7 @@ ZEND_API int _zend_hash_index_update_or_next_insert(HashTable *ht, ulong h, void
 }
 
 
-static int zend_hash_do_resize(HashTable *ht)
+static void zend_hash_do_resize(HashTable *ht)
 {
        Bucket **t;
 #ifdef ZEND_SIGNALS
@@ -447,19 +428,14 @@ static int zend_hash_do_resize(HashTable *ht)
        IS_CONSISTENT(ht);
 
        if ((ht->nTableSize << 1) > 0) {        /* Let's double the table size */
-               t = (Bucket **) perealloc_recoverable(ht->arBuckets, (ht->nTableSize << 1) * sizeof(Bucket *), ht->persistent);
-               if (t) {
-                       HANDLE_BLOCK_INTERRUPTIONS();
-                       ht->arBuckets = t;
-                       ht->nTableSize = (ht->nTableSize << 1);
-                       ht->nTableMask = ht->nTableSize - 1;
-                       zend_hash_rehash(ht);
-                       HANDLE_UNBLOCK_INTERRUPTIONS();
-                       return SUCCESS;
-               }
-               return FAILURE;
+               t = (Bucket **) perealloc(ht->arBuckets, (ht->nTableSize << 1) * sizeof(Bucket *), ht->persistent);
+               HANDLE_BLOCK_INTERRUPTIONS();
+               ht->arBuckets = t;
+               ht->nTableSize = (ht->nTableSize << 1);
+               ht->nTableMask = ht->nTableSize - 1;
+               zend_hash_rehash(ht);
+               HANDLE_UNBLOCK_INTERRUPTIONS();
        }
-       return SUCCESS;
 }
 
 ZEND_API int zend_hash_rehash(HashTable *ht)
@@ -1449,9 +1425,6 @@ ZEND_API int zend_hash_sort(HashTable *ht, sort_func_t sort_func,
                return SUCCESS;
        }
        arTmp = (Bucket **) pemalloc(ht->nNumOfElements * sizeof(Bucket *), ht->persistent);
-       if (!arTmp) {
-               return FAILURE;
-       }
        p = ht->pListHead;
        i = 0;
        while (p) {