Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4638f7b
Change "foreach" statement behavior (this is just a PoC yet)
dstogov Jan 28, 2015
dd2a36a
Use GET_OP1_ZVAL_PTR_DEREF() (IS_TMP_VAR and IS_CONST can't be IS_REF…
dstogov Jan 28, 2015
92e90c0
Fixed operand destruction in case of exceptions in iterator
dstogov Jan 28, 2015
61e7391
Fixed temporary variable re-allocation pass
dstogov Jan 28, 2015
eef80c5
Fixed foreach by reference iteration over constant array
dstogov Jan 28, 2015
994d435
Merge branch 'master' into foreach
dstogov Jan 28, 2015
2705d17
Merge branch 'master' into foreach
dstogov Jan 29, 2015
10a3260
New test
dstogov Jan 29, 2015
15a23b1
Reimplement iteration magic with HashTableIterators (see https://wiki…
dstogov Jan 29, 2015
721fc9e
Added new test
dstogov Jan 29, 2015
621fd74
Merge branch 'master' into foreach
dstogov Jan 30, 2015
4c5b385
More careful iterators update.
dstogov Jan 30, 2015
5aa9712
Implement consistent behavior for foreach by value over plain object
dstogov Jan 30, 2015
cc4b7be
Make internal function, operation on array passed by reference, to pr…
dstogov Jan 30, 2015
08302c0
Make array_splice() to preserve foreach hash position
dstogov Jan 30, 2015
fb2d079
API cleanup
dstogov Jan 30, 2015
b37f1d5
Fixed test name
dstogov Jan 30, 2015
5406f21
Reduced alghorithms complexity
dstogov Jan 30, 2015
1e41295
Generalize HashTableIterator API to allows its usage without iinvolve…
dstogov Jan 31, 2015
6c168e5
Merge branch 'master' into foreach
dstogov Feb 2, 2015
9d17a42
Merge branch 'master' into foreach
dstogov Feb 5, 2015
79b8bb1
Merge branch 'master' into foreach
dstogov Feb 9, 2015
7a50a32
Merge branch 'master' into foreach
dstogov Feb 11, 2015
b00f3bd
Merge branch 'master' into foreach
dstogov Feb 12, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reduced alghorithms complexity
  • Loading branch information
dstogov committed Jan 30, 2015
commit 5406f21b11e563069d64045e599693b51c444b63
36 changes: 29 additions & 7 deletions ext/standard/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1898,13 +1898,18 @@ static void php_array_data_shuffle(zval *array) /* {{{ */
}
}
} else {
uint32_t iter_pos = zend_hash_iterators_lower_pos(hash, 0);

if (hash->nNumUsed != hash->nNumOfElements) {
for (j = 0, idx = 0; idx < hash->nNumUsed; idx++) {
p = hash->arData + idx;
if (Z_TYPE(p->val) == IS_UNDEF) continue;
if (j != idx) {
hash->arData[j] = *p;
zend_hash_iterators_update(hash, idx, j);
if (idx == iter_pos) {
zend_hash_iterators_update(hash, idx, j);
iter_pos = zend_hash_iterators_lower_pos(hash, iter_pos + 1);
}
}
j++;
}
Expand Down Expand Up @@ -1964,6 +1969,7 @@ static void php_splice(HashTable *in_hash, int offset, int length, HashTable *re
uint idx;
Bucket *p; /* Pointer to hash bucket */
zval *entry; /* Hash entry */
uint32_t iter_pos = zend_hash_iterators_lower_pos(in_hash, 0);

/* Get number of entries in the input hash */
num_in = zend_hash_num_elements(in_hash);
Expand Down Expand Up @@ -1998,8 +2004,11 @@ static void php_splice(HashTable *in_hash, int offset, int length, HashTable *re
} else {
zend_hash_add_new(&out_hash, p->key, entry);
}
if (idx != pos) {
zend_hash_iterators_update(in_hash, idx, pos);
if (idx == iter_pos) {
if (idx != pos) {
zend_hash_iterators_update(in_hash, idx, pos);
}
iter_pos = zend_hash_iterators_lower_pos(in_hash, iter_pos + 1);
}
pos++;
}
Expand Down Expand Up @@ -2044,6 +2053,7 @@ static void php_splice(HashTable *in_hash, int offset, int length, HashTable *re
}
}
}
iter_pos = zend_hash_iterators_lower_pos(in_hash, iter_pos);

/* If there are entries to insert.. */
if (replace) {
Expand All @@ -2064,8 +2074,11 @@ static void php_splice(HashTable *in_hash, int offset, int length, HashTable *re
} else {
zend_hash_add_new(&out_hash, p->key, entry);
}
if (idx != pos) {
zend_hash_iterators_update(in_hash, idx, pos);
if (idx == iter_pos) {
if (idx != pos) {
zend_hash_iterators_update(in_hash, idx, pos);
}
iter_pos = zend_hash_iterators_lower_pos(in_hash, iter_pos + 1);
}
pos++;
}
Expand Down Expand Up @@ -2252,6 +2265,8 @@ PHP_FUNCTION(array_shift)
k++;
}
} else {
uint32_t iter_pos = zend_hash_iterators_lower_pos(Z_ARRVAL_P(stack), 0);

for (idx = 0; idx < Z_ARRVAL_P(stack)->nNumUsed; idx++) {
p = Z_ARRVAL_P(stack)->arData + idx;
if (Z_TYPE(p->val) == IS_UNDEF) continue;
Expand All @@ -2261,7 +2276,10 @@ PHP_FUNCTION(array_shift)
q->key = NULL;
ZVAL_COPY_VALUE(&q->val, &p->val);
ZVAL_UNDEF(&p->val);
zend_hash_iterators_update(Z_ARRVAL_P(stack), idx, k);
if (idx == iter_pos) {
zend_hash_iterators_update(Z_ARRVAL_P(stack), idx, k);
iter_pos = zend_hash_iterators_lower_pos(Z_ARRVAL_P(stack), iter_pos + 1);
}
}
k++;
}
Expand Down Expand Up @@ -2328,6 +2346,7 @@ PHP_FUNCTION(array_unshift)
} else {
uint32_t old_idx;
uint32_t new_idx = i;
uint32_t iter_pos = zend_hash_iterators_lower_pos(Z_ARRVAL_P(stack), 0);

ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(stack), key, value) {
if (key) {
Expand All @@ -2336,7 +2355,10 @@ PHP_FUNCTION(array_unshift)
zend_hash_next_index_insert_new(&new_hash, value);
}
old_idx = (Bucket*)value - Z_ARRVAL_P(stack)->arData;
zend_hash_iterators_update(Z_ARRVAL_P(stack), old_idx, new_idx);
if (old_idx == iter_pos) {
zend_hash_iterators_update(Z_ARRVAL_P(stack), old_idx, new_idx);
iter_pos = zend_hash_iterators_lower_pos(Z_ARRVAL_P(stack), iter_pos + 1);
}
new_idx++;
} ZEND_HASH_FOREACH_END();
}
Expand Down