summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorBob Weinand <bobwei9@hotmail.com>2015-05-15 22:45:35 +0200
committerBob Weinand <bobwei9@hotmail.com>2015-05-15 22:45:35 +0200
commit34e6fbbfed6bd63e7f71ca61ff73ca67d0c12b7b (patch)
treef9c20aa7c8a55c9670ee4d456e895679c80fb45e /ext
parent6868b56e25e6ce80418219bd876ee2de7646cf63 (diff)
parent230b435ed40fe40931ae3f32f319cfff328ac2fe (diff)
downloadphp-git-34e6fbbfed6bd63e7f71ca61ff73ca67d0c12b7b.tar.gz
Merge branch 'master' of https://github.com/php/php-src
Diffstat (limited to 'ext')
-rw-r--r--ext/gettext/gettext.c4
-rw-r--r--ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt21
-rw-r--r--ext/standard/string.c70
3 files changed, 39 insertions, 56 deletions
diff --git a/ext/gettext/gettext.c b/ext/gettext/gettext.c
index 90038fad5c..44502729e5 100644
--- a/ext/gettext/gettext.c
+++ b/ext/gettext/gettext.c
@@ -139,13 +139,13 @@ ZEND_GET_MODULE(php_gettext)
#define PHP_GETTEXT_MAX_MSGID_LENGTH 4096
#define PHP_GETTEXT_DOMAIN_LENGTH_CHECK \
- if (domain_len > PHP_GETTEXT_MAX_DOMAIN_LENGTH) { \
+ if (UNEXPECTED(domain_len > PHP_GETTEXT_MAX_DOMAIN_LENGTH)) { \
php_error_docref(NULL, E_WARNING, "domain passed too long"); \
RETURN_FALSE; \
}
#define PHP_GETTEXT_LENGTH_CHECK(check_name, check_len) \
- if (check_len > PHP_GETTEXT_MAX_MSGID_LENGTH) { \
+ if (UNEXPECTED(check_len > PHP_GETTEXT_MAX_MSGID_LENGTH)) { \
php_error_docref(NULL, E_WARNING, "%s passed too long", check_name); \
RETURN_FALSE; \
}
diff --git a/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt b/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt
index 876109001c..508f73ee55 100644
--- a/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt
+++ b/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt
@@ -9,7 +9,7 @@ var_dump($ext->getClasses());
?>
==DONE==
--EXPECT--
-array(12) {
+array(13) {
["ReflectionException"]=>
object(ReflectionClass)#2 (1) {
["name"]=>
@@ -35,38 +35,43 @@ array(12) {
["name"]=>
string(18) "ReflectionFunction"
}
- ["ReflectionParameter"]=>
+ ["ReflectionGenerator"]=>
object(ReflectionClass)#7 (1) {
["name"]=>
+ string(19) "ReflectionGenerator"
+ }
+ ["ReflectionParameter"]=>
+ object(ReflectionClass)#8 (1) {
+ ["name"]=>
string(19) "ReflectionParameter"
}
["ReflectionMethod"]=>
- object(ReflectionClass)#8 (1) {
+ object(ReflectionClass)#9 (1) {
["name"]=>
string(16) "ReflectionMethod"
}
["ReflectionClass"]=>
- object(ReflectionClass)#9 (1) {
+ object(ReflectionClass)#10 (1) {
["name"]=>
string(15) "ReflectionClass"
}
["ReflectionObject"]=>
- object(ReflectionClass)#10 (1) {
+ object(ReflectionClass)#11 (1) {
["name"]=>
string(16) "ReflectionObject"
}
["ReflectionProperty"]=>
- object(ReflectionClass)#11 (1) {
+ object(ReflectionClass)#12 (1) {
["name"]=>
string(18) "ReflectionProperty"
}
["ReflectionExtension"]=>
- object(ReflectionClass)#12 (1) {
+ object(ReflectionClass)#13 (1) {
["name"]=>
string(19) "ReflectionExtension"
}
["ReflectionZendExtension"]=>
- object(ReflectionClass)#13 (1) {
+ object(ReflectionClass)#14 (1) {
["name"]=>
string(23) "ReflectionZendExtension"
}
diff --git a/ext/standard/string.c b/ext/standard/string.c
index ee66e8a2af..3162533186 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -2977,19 +2977,20 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p
int num_keys = 0;
size_t minlen = 128*1024;
size_t maxlen = 0;
- HashTable str_hash, num_hash;
+ HashTable str_hash;
zval *entry, tmp, dummy;
char *key;
smart_str result = {0};
zend_ulong bitset[256/sizeof(zend_ulong)];
+ zend_ulong *num_bitset;
/* we will collect all possible key lengths */
ZVAL_NULL(&dummy);
- zend_hash_init(&num_hash, 8, NULL, NULL, 0);
+ num_bitset = ecalloc((slen + (sizeof(zend_ulong)-1)) / sizeof(zend_ulong), sizeof(zend_ulong));
memset(bitset, 0, sizeof(bitset));
/* check if original array has numeric keys */
- ZEND_HASH_FOREACH_KEY(pats, num_key, str_key) {
+ ZEND_HASH_FOREACH_STR_KEY(pats, str_key) {
if (UNEXPECTED(!str_key)) {
num_keys = 1;
} else {
@@ -3007,12 +3008,12 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p
minlen = len;
}
/* remember possible key length */
- zend_hash_index_add(&num_hash, len, &dummy);
+ num_bitset[len / sizeof(zend_ulong)] |= Z_UL(1) << (len % sizeof(zend_ulong));
bitset[((unsigned char)str_key->val[0]) / sizeof(zend_ulong)] |= Z_UL(1) << (((unsigned char)str_key->val[0]) % sizeof(zend_ulong));
}
} ZEND_HASH_FOREACH_END();
- if (num_keys) {
+ if (UNEXPECTED(num_keys)) {
/* we have to rebuild HashTable with numeric keys */
zend_hash_init(&str_hash, zend_hash_num_elements(pats), NULL, NULL, 0);
ZEND_HASH_FOREACH_KEY_VAL(pats, num_key, str_key, entry) {
@@ -3033,7 +3034,7 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p
minlen = len;
}
/* remember possible key length */
- zend_hash_index_add(&num_hash, len, &dummy);
+ num_bitset[len / sizeof(zend_ulong)] |= Z_UL(1) << (len % sizeof(zend_ulong));
bitset[((unsigned char)str_key->val[0]) / sizeof(zend_ulong)] |= Z_UL(1) << (((unsigned char)str_key->val[0]) % sizeof(zend_ulong));
} else {
len = str_key->len;
@@ -3055,45 +3056,20 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p
if (pats == &str_hash) {
zend_hash_destroy(&str_hash);
}
- zend_hash_destroy(&num_hash);
- RETURN_STRINGL(str, slen);
- }
- /* select smart or simple algorithm */
- // TODO: tune the condition ???
- len = zend_hash_num_elements(&num_hash);
- if ((maxlen - (minlen - 1) - len > 0) &&
- /* smart algorithm, sort key lengths first */
- zend_hash_sort(&num_hash, php_strtr_key_compare, 0) == SUCCESS) {
-
- old_pos = pos = 0;
- while (pos <= slen - minlen) {
- key = str + pos;
- ZEND_HASH_FOREACH_NUM_KEY(&num_hash, len) {
- if (len > slen - pos) continue;
- if ((bitset[((unsigned char)key[0]) / sizeof(zend_ulong)] & Z_UL(1) << (((unsigned char)key[0]) % sizeof(zend_ulong))) == 0) continue;
- entry = zend_hash_str_find(pats, key, len);
- if (entry != NULL) {
- zend_string *s = zval_get_string(entry);
- smart_str_appendl(&result, str + old_pos, pos - old_pos);
- smart_str_append(&result, s);
- old_pos = pos + len;
- pos = old_pos - 1;
- zend_string_release(s);
- break;
- }
- } ZEND_HASH_FOREACH_END();
- pos++;
- }
- } else {
- /* use simple algorithm */
- old_pos = pos = 0;
- while (pos <= slen - minlen) {
- if (maxlen > slen - pos) {
- maxlen = slen - pos;
+ efree(num_bitset);
+ RETURN_STR_COPY(input);
+ }
+
+ old_pos = pos = 0;
+ while (pos <= slen - minlen) {
+ key = str + pos;
+ if (bitset[((unsigned char)key[0]) / sizeof(zend_ulong)] & Z_UL(1) << (((unsigned char)key[0]) % sizeof(zend_ulong))) {
+ len = maxlen;
+ if (len > slen - pos) {
+ len = slen - pos;
}
- key = str + pos;
- for (len = maxlen; len >= minlen; len--) {
- if ((bitset[((unsigned char)key[0]) / sizeof(zend_ulong)] & Z_UL(1) << (((unsigned char)key[0]) % sizeof(zend_ulong))) == 0) continue;
+ while (len >= minlen) {
+ if (num_bitset[len / sizeof(zend_ulong)] & Z_UL(1) << (len % sizeof(zend_ulong)) == 0) continue;
entry = zend_hash_str_find(pats, key, len);
if (entry != NULL) {
zend_string *s = zval_get_string(entry);
@@ -3104,10 +3080,12 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p
zend_string_release(s);
break;
}
+ len--;
}
- pos++;
}
+ pos++;
}
+
if (result.s) {
smart_str_appendl(&result, str + old_pos, slen - old_pos);
smart_str_0(&result);
@@ -3120,7 +3098,7 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p
if (pats == &str_hash) {
zend_hash_destroy(&str_hash);
}
- zend_hash_destroy(&num_hash);
+ efree(num_bitset);
}
/* }}} */