com php-src: Optimized array_slice: ext/standard/array. c
| From: | Xinchen Hui | Date: | Fri, 16 Jan 2015 09:54:50 +0000 |
| Subject: | com php-src: Optimized array_slice: ext/standard/array. c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-84132@lists.php.net to get a copy of this message | ||
Commit: 865749e7b15176e5f601d7a4a35f18b829fdc5c2
Author: Xinchen Hui <laruence@php.net> Fri, 16 Jan 2015 17:54:50 +0800
Parents: 22084e1478647b18c3c2f64348db7d573789b3c0
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=865749e7b15176e5f601d7a4a35f18b829fdc5c2
Log:
Optimized array_slice
Changed paths:
M ext/standard/array.c
Diff:
diff --git a/ext/standard/array.c b/ext/standard/array.c
index ae56fd4..5662dee 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -2367,26 +2367,43 @@ PHP_FUNCTION(array_slice)
/* Start at the beginning and go until we hit offset */
pos = 0;
- ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, string_key, entry) {
- pos++;
- if (pos <= offset) {
- continue;
- }
- if (pos > offset + length) {
- break;
- }
+ if (!preserve_keys && (Z_ARRVAL_P(input)->u.flags & HASH_FLAG_PACKED)) {
+ zend_hash_real_init(Z_ARRVAL_P(return_value), 1);
+ ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) {
+ ZEND_HASH_FOREACH_NUM_KEY_VAL(Z_ARRVAL_P(input), num_key, entry) {
+ pos++;
+ if (pos <= offset) {
+ continue;
+ }
+ if (pos > offset + length) {
+ break;
+ }
+ ZEND_HASH_FILL_ADD(entry);
+ zval_add_ref(entry);
+ } ZEND_HASH_FOREACH_END();
+ } ZEND_HASH_FILL_END();
+ } else {
+ ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, string_key, entry) {
+ pos++;
+ if (pos <= offset) {
+ continue;
+ }
+ if (pos > offset + length) {
+ break;
+ }
- if (string_key) {
- entry = zend_hash_add_new(Z_ARRVAL_P(return_value), string_key, entry);
- } else {
- if (preserve_keys) {
- entry = zend_hash_index_add_new(Z_ARRVAL_P(return_value), num_key, entry);
+ if (string_key) {
+ entry = zend_hash_add_new(Z_ARRVAL_P(return_value), string_key, entry);
} else {
- entry = zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), entry);
+ if (preserve_keys) {
+ entry = zend_hash_index_add_new(Z_ARRVAL_P(return_value), num_key, entry);
+ } else {
+ entry = zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), entry);
+ }
}
- }
- zval_add_ref(entry);
- } ZEND_HASH_FOREACH_END();
+ zval_add_ref(entry);
+ } ZEND_HASH_FOREACH_END();
+ }
}
/* }}} */