Skip to content

Commit

Permalink
Optimize array unpersist
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Oct 8, 2018
1 parent 4bfd0e7 commit 9a630e3
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions apc_persist.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,16 +520,32 @@ static zend_array *apc_unpersist_ht(
}

HT_SET_DATA_ADDR(ht, emalloc(HT_SIZE(ht)));
memcpy(HT_GET_DATA_ADDR(ht), HT_GET_DATA_ADDR(orig_ht), HT_USED_SIZE(ht));

for (idx = 0; idx < ht->nNumUsed; idx++) {
Bucket *p = ht->arData + idx;
if (Z_TYPE(p->val) == IS_UNDEF) continue;
memcpy(HT_GET_DATA_ADDR(ht), HT_GET_DATA_ADDR(orig_ht), HT_HASH_SIZE(ht->nTableMask));

if (ht->u.flags & HASH_FLAG_STATIC_KEYS) {
Bucket *p = ht->arData, *q = orig_ht->arData, *p_end = p + ht->nNumUsed;
for (; p < p_end; p++, q++) {
/* No need to check for UNDEF, as unpersist_zval can be safely called on UNDEF */
*p = *q;
apc_unpersist_zval(ctxt, &p->val);
}
} else {
Bucket *p = ht->arData, *q = orig_ht->arData, *p_end = p + ht->nNumUsed;
for (; p < p_end; p++, q++) {
if (Z_TYPE(q->val) == IS_UNDEF) {
ZVAL_UNDEF(&p->val);
continue;
}

if (p->key) {
p->key = zend_string_dup(p->key, 0);
p->val = q->val;
p->h = q->h;
if (q->key) {
p->key = zend_string_dup(q->key, 0);
} else {
p->key = NULL;
}
apc_unpersist_zval(ctxt, &p->val);
}
apc_unpersist_zval(ctxt, &p->val);
}

return ht;
Expand Down

0 comments on commit 9a630e3

Please sign in to comment.