Skip to content

Commit 5c4bff6

Browse files
authored
main: convert sys_temp_dir global to zend_string* (#22812)
This removes a strlen() call when we already know the length of the string
1 parent 8d9ed39 commit 5c4bff6

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

main/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ PHP_INI_BEGIN()
839839
STD_PHP_INI_ENTRY("error_log", NULL, PHP_INI_ALL, OnUpdateErrorLog, error_log, php_core_globals, core_globals)
840840
STD_PHP_INI_ENTRY("error_log_mode", "0644", PHP_INI_ALL, OnUpdateLong, error_log_mode, php_core_globals, core_globals)
841841
STD_PHP_INI_ENTRY("extension_dir", PHP_EXTENSION_DIR, PHP_INI_SYSTEM, OnUpdateStringUnempty, extension_dir, php_core_globals, core_globals)
842-
STD_PHP_INI_ENTRY("sys_temp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStringUnempty, sys_temp_dir, php_core_globals, core_globals)
842+
STD_PHP_INI_ENTRY("sys_temp_dir", NULL, PHP_INI_SYSTEM, OnUpdateStrNotEmpty, sys_temp_dir, php_core_globals, core_globals)
843843
STD_PHP_INI_ENTRY("include_path", PHP_INCLUDE_PATH, PHP_INI_ALL, OnUpdateStringUnempty, include_path, php_core_globals, core_globals)
844844
PHP_INI_ENTRY("max_execution_time", "30", PHP_INI_ALL, OnUpdateTimeout)
845845
STD_PHP_INI_ENTRY("open_basedir", NULL, PHP_INI_ALL, OnUpdateBaseDir, open_basedir, php_core_globals, core_globals)

main/php_globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct _php_core_globals {
8383
bool open_basedir_modified;
8484
char *extension_dir;
8585
char *php_binary;
86-
char *sys_temp_dir;
86+
zend_string *sys_temp_dir;
8787

8888
char *upload_tmp_dir;
8989
zend_long upload_max_filesize;

main/php_open_temporary_file.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,14 @@ PHPAPI const char* php_get_temporary_directory(void)
240240

241241
/* Is there a temporary directory "sys_temp_dir" in .ini defined? */
242242
{
243-
char *sys_temp_dir = PG(sys_temp_dir);
243+
const zend_string *sys_temp_dir = PG(sys_temp_dir);
244244
if (sys_temp_dir) {
245-
size_t len = strlen(sys_temp_dir);
246-
if (len >= 2 && sys_temp_dir[len - 1] == DEFAULT_SLASH) {
247-
PG(php_sys_temp_dir) = estrndup(sys_temp_dir, len - 1);
245+
size_t len = ZSTR_LEN(sys_temp_dir);
246+
if (len >= 2 && ZSTR_VAL(sys_temp_dir)[len - 1] == DEFAULT_SLASH) {
247+
PG(php_sys_temp_dir) = estrndup(ZSTR_VAL(sys_temp_dir), len - 1);
248248
return PG(php_sys_temp_dir);
249-
} else if (len >= 1 && sys_temp_dir[len - 1] != DEFAULT_SLASH) {
250-
PG(php_sys_temp_dir) = estrndup(sys_temp_dir, len);
249+
} else if (len >= 1 && ZSTR_VAL(sys_temp_dir)[len - 1] != DEFAULT_SLASH) {
250+
PG(php_sys_temp_dir) = estrndup(ZSTR_VAL(sys_temp_dir), len);
251251
return PG(php_sys_temp_dir);
252252
}
253253
}

0 commit comments

Comments
 (0)