zval tmp;
zend_string *str;
- if (Z_TYPE_P(dim) != IS_LONG) {
+ if (UNEXPECTED(Z_TYPE_P(dim) != IS_LONG)) {
switch(Z_TYPE_P(dim)) {
/* case IS_LONG: */
case IS_STRING:
dim = &tmp;
}
- if (Z_LVAL_P(dim) < 0 || Z_STRLEN_P(container) <= Z_LVAL_P(dim)) {
+ if (UNEXPECTED(Z_LVAL_P(dim) < 0) || UNEXPECTED(Z_STRLEN_P(container) <= Z_LVAL_P(dim))) {
if (type != BP_VAR_IS) {
zend_error(E_NOTICE, "Uninitialized string offset: %ld", Z_LVAL_P(dim));
}
str = STR_EMPTY_ALLOC();
} else {
- str = STR_INIT(Z_STRVAL_P(container) + Z_LVAL_P(dim), 1, 0);
+ zend_uchar c = (zend_uchar)Z_STRVAL_P(container)[Z_LVAL_P(dim)];
+
+ if (CG(one_char_string)[c]) {
+ str = CG(one_char_string)[c];
+ } else {
+ str = STR_INIT(Z_STRVAL_P(container) + Z_LVAL_P(dim), 1, 0);
+ }
}
ZVAL_STR(result, str);
return;
zend_stack context_stack;
zend_string *empty_string;
+ zend_string *one_char_string[256];
HashTable interned_strings;
str = STR_ALLOC(sizeof("")-1, 1);
str->val[0] = '\000';
CG(empty_string) = zend_new_interned_string_int(str TSRMLS_CC);
+
+ /* one char strings (the actual interned strings are going to be created by ext/opcache) */
+ memset(CG(one_char_string), 0, sizeof(CG(one_char_string)));
#else
str = STR_ALLOC(sizeof("")-1, 1);
str->val[0] = '\000';
#if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
/* empty string */
CG(empty_string) = accel_new_interned_string(CG(empty_string) TSRMLS_CC);
+ for (j = 0; j < 256; j++) {
+ char s[2];
+ s[0] = j;
+ s[1] = 0;
+ CG(one_char_string)[j] = accel_new_interned_string(STR_INIT(s, 1, 0) TSRMLS_CC);
+ }
#endif
/* function table hash keys */