com php-src: Avoid useless allocations: Zend/zend_hash.h
| From: | Dmitry Stogov | Date: | Fri, 25 Apr 2014 07:29:18 +0000 |
| Subject: | com php-src: Avoid useless allocations: Zend/zend_hash.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-77281@lists.php.net to get a copy of this message | ||
Commit: 42a33085c8fe320ddf555d270cf0bae94af83f92
Author: Dmitry Stogov <dmitry@zend.com> Fri, 25 Apr 2014 11:29:18 +0400
Parents: d0ed1212a454dbbae7ec0327bc4f063e26037a0b
Branches: phpng
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=42a33085c8fe320ddf555d270cf0bae94af83f92
Log:
Avoid useless allocations
Changed paths:
M Zend/zend_hash.h
Diff:
diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h
index 54575c2..3db7abd 100644
--- a/Zend/zend_hash.h
+++ b/Zend/zend_hash.h
@@ -417,27 +417,27 @@ static inline void *zend_hash_str_update_ptr(HashTable *ht, const char *str,
int
static inline void *zend_hash_add_mem(HashTable *ht, zend_string *key, void *pData, size_t size)
{
- void *p, *r;
+ zval tmp, *zv;
- p = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
- memcpy(p, pData, size);
- if ((r = zend_hash_add_ptr(ht, key, p))) {
- return r;
+ ZVAL_PTR(&tmp, NULL);
+ if ((zv = zend_hash_add(ht, key, &tmp))) {
+ Z_PTR_P(zv) = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
+ memcpy(Z_PTR_P(zv), pData, size);
+ return Z_PTR_P(zv);
}
- pefree(p, ht->u.flags & HASH_FLAG_PERSISTENT);
return NULL;
}
static inline void *zend_hash_str_add_mem(HashTable *ht, const char *str, int len, void *pData,
size_t size)
{
- void *p, *r;
+ zval tmp, *zv;
- p = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
- memcpy(p, pData, size);
- if ((r = zend_hash_str_add_ptr(ht, str, len, p))) {
- return r;
+ ZVAL_PTR(&tmp, NULL);
+ if ((zv = zend_hash_str_add(ht, str, len, &tmp))) {
+ Z_PTR_P(zv) = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
+ memcpy(Z_PTR_P(zv), pData, size);
+ return Z_PTR_P(zv);
}
- pefree(p, ht->u.flags & HASH_FLAG_PERSISTENT);
return NULL;
}
@@ -488,14 +488,14 @@ static inline void *zend_hash_index_update_mem(HashTable *ht, ulong h, void
*pDa
static inline void *zend_hash_next_index_insert_mem(HashTable *ht, void *pData, size_t size)
{
- void *p, *r;
+ zval tmp, *zv;
- p = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
- memcpy(p, pData, size);
- if ((r = zend_hash_next_index_insert_ptr(ht, p))) {
- return r;
+ ZVAL_PTR(&tmp, NULL);
+ if ((zv = zend_hash_next_index_insert(ht, &tmp))) {
+ Z_PTR_P(zv) = pemalloc(size, ht->u.flags & HASH_FLAG_PERSISTENT);
+ memcpy(Z_PTR_P(zv), pData, size);
+ return Z_PTR_P(zv);
}
- pefree(p, ht->u.flags & HASH_FLAG_PERSISTENT);
return NULL;
}