com php-src: Avoid temporary string creation and destruction.: Zend/zend_ini.c Zend/zend_ini.h ext/standard/basic _functions.c

From: Date: Mon, 11 Dec 2017 15:18:30 +0000
Subject: com php-src: Avoid temporary string creation and destruction.: Zend/zend_ini.c Zend/zend_ini.h ext/standard/basic _functions.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-100554@lists.php.net to get a copy of this message
Commit: dc47171523b70112b14cf9144bdf223e9db550fe Author: Dmitry Stogov <dmitry@zend.com> Mon, 11 Dec 2017 18:18:30 +0300 Parents: 9f1e9700580245088d43cd6eef50edce3bce7abc Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=dc47171523b70112b14cf9144bdf223e9db550fe Log: Avoid temporary string creation and destruction. Changed paths: M Zend/zend_ini.c M Zend/zend_ini.h M ext/standard/basic_functions.c Diff: diff --git a/Zend/zend_ini.c b/Zend/zend_ini.c index 129c782..cb711cb 100644 --- a/Zend/zend_ini.c +++ b/Zend/zend_ini.c @@ -496,6 +496,19 @@ ZEND_API char *zend_ini_string(char *name, size_t name_length, int orig) /* {{{ } /* }}} */ +ZEND_API zend_string *zend_ini_get_value(zend_string *name) /* {{{ */ +{ + zend_ini_entry *ini_entry; + + ini_entry = zend_hash_find_ptr(EG(ini_directives), name); + if (ini_entry) { + return ini_entry->value ? ini_entry->value : ZSTR_EMPTY_ALLOC(); + } else { + return NULL; + } +} +/* }}} */ + #if TONY_20070307 static void zend_ini_displayer_cb(zend_ini_entry *ini_entry, int type) /* {{{ */ { diff --git a/Zend/zend_ini.h b/Zend/zend_ini.h index 8f91ef0..cfea8da 100644 --- a/Zend/zend_ini.h +++ b/Zend/zend_ini.h @@ -87,6 +87,7 @@ ZEND_API zend_long zend_ini_long(char *name, size_t name_length, int orig); ZEND_API double zend_ini_double(char *name, size_t name_length, int orig); ZEND_API char *zend_ini_string(char *name, size_t name_length, int orig); ZEND_API char *zend_ini_string_ex(char *name, size_t name_length, int orig, zend_bool *exists); +ZEND_API zend_string *zend_ini_get_value(zend_string *name); ZEND_API int zend_ini_register_displayer(char *name, uint32_t name_length, void (*displayer)(zend_ini_entry *ini_entry, int type)); diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 278ed08..f904a2a 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -5352,26 +5352,29 @@ PHP_FUNCTION(highlight_string) Get a configuration option */ PHP_FUNCTION(ini_get) { - char *varname, *str; - size_t varname_len, len; + zend_string *varname, *val; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_STRING(varname, varname_len) + Z_PARAM_STR(varname) ZEND_PARSE_PARAMETERS_END(); - str = zend_ini_string(varname, (uint32_t)varname_len, 0); + val = zend_ini_get_value(varname); - if (!str) { + if (!val) { RETURN_FALSE; } - len = strlen(str); - if (len == 0) { - RETURN_EMPTY_STRING(); - } else if (len == 1) { - RETURN_INTERNED_STR(ZSTR_CHAR((zend_uchar)str[0])); + if (ZSTR_IS_INTERNED(val)) { + RETVAL_INTERNED_STR(val); + } else if (ZSTR_LEN(val) == 0) { + RETVAL_EMPTY_STRING(); + } else if (ZSTR_LEN(val) == 1) { + RETVAL_INTERNED_STR(ZSTR_CHAR((zend_uchar)ZSTR_VAL(val)[0])); + } else if (!(GC_FLAGS(val) & GC_PERSISTENT)) { + ZVAL_NEW_STR(return_value, zend_string_copy(val)); + } else { + ZVAL_NEW_STR(return_value, zend_string_init(ZSTR_VAL(val), ZSTR_LEN(val), 0)); } - RETURN_STRINGL(str, len); } /* }}} */ @@ -5471,25 +5474,27 @@ PHP_FUNCTION(ini_set) { zend_string *varname; zend_string *new_value; - char *old_value; + zend_string *val; ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_STR(varname) Z_PARAM_STR(new_value) ZEND_PARSE_PARAMETERS_END(); - old_value = zend_ini_string(ZSTR_VAL(varname), ZSTR_LEN(varname), 0); + val = zend_ini_get_value(varname); /* copy to return here, because alter might free it! */ - if (old_value) { - size_t len = strlen(old_value); - - if (len == 0) { + if (val) { + if (ZSTR_IS_INTERNED(val)) { + RETVAL_INTERNED_STR(val); + } else if (ZSTR_LEN(val) == 0) { RETVAL_EMPTY_STRING(); - } else if (len == 1) { - RETVAL_INTERNED_STR(ZSTR_CHAR((zend_uchar)old_value[0])); + } else if (ZSTR_LEN(val) == 1) { + RETVAL_INTERNED_STR(ZSTR_CHAR((zend_uchar)ZSTR_VAL(val)[0])); + } else if (!(GC_FLAGS(val) & GC_PERSISTENT)) { + ZVAL_NEW_STR(return_value, zend_string_copy(val)); } else { - RETVAL_STRINGL(old_value, len); + ZVAL_NEW_STR(return_value, zend_string_init(ZSTR_VAL(val), ZSTR_LEN(val), 0)); } } else { RETVAL_FALSE;

« previous php.cvs (#100554) next »