Commit: ae91084067cbbd2a1afaf62913d1913a6edc2c13 Author: Nikita Popov <ni...@php.net> Mon, 17 Jun 2013 18:51:59 +0200 Parents: ca660c2f778da0bc2e24295eba674351d407a854 Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=ae91084067cbbd2a1afaf62913d1913a6edc2c13 Log: Remove unnecessary NULL checks from zend_hash Our memory allocation functions (including the persistent ones) are infallible, so no need to check for NULL. Changed paths: M Zend/zend_hash.c Diff: diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index 27b603e..1369242 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -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) { -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php