com php-src: Avoid potentially superfluous string reallocation: ext/com_dotnet/com_typeinfo.c

From: Date: Fri, 22 Feb 2019 09:35:19 +0000
Subject: com php-src: Avoid potentially superfluous string reallocation: ext/com_dotnet/com_typeinfo.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-104824@lists.php.net to get a copy of this message
Commit: 427ebce6295b296c1f18f6bd927bf3cd295be815 Author: Christoph M. Becker <cmbecker69@gmx.de> Fri, 22 Feb 2019 10:18:39 +0100 Parents: a37c92659100e08bbc19cdf4aad3b56e43ef85d4 Branches: PHP-7.4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=427ebce6295b296c1f18f6bd927bf3cd295be815 Log: Avoid potentially superfluous string reallocation If we're not going to register the constant, it makes no sense to allocate a zend_string and free it shortly after.. Changed paths: M ext/com_dotnet/com_typeinfo.c Diff: diff --git a/ext/com_dotnet/com_typeinfo.c b/ext/com_dotnet/com_typeinfo.c index 1170213..517e04e 100644 --- a/ext/com_dotnet/com_typeinfo.c +++ b/ext/com_dotnet/com_typeinfo.c @@ -184,23 +184,15 @@ PHP_COM_DOTNET_API int php_com_import_typelib(ITypeLib *TL, int mode, int codepa } const_name = php_com_olestring_to_string(bstr_ids, &len, codepage); - c.name = zend_string_init(const_name, len, mode & CONST_PERSISTENT); - // TODO: avoid reallocation??? - efree(const_name); - if(c.name == NULL) { - ITypeInfo_ReleaseVarDesc(TypeInfo, pVarDesc); - continue; - } -//??? c.name_len++; /* include NUL */ SysFreeString(bstr_ids); /* sanity check for the case where the constant is already defined */ php_com_zval_from_variant(&value, pVarDesc->lpvarValue, codepage); - if ((exists = zend_get_constant(c.name)) != NULL) { + if ((exists = zend_get_constant_str(const_name, len)) != NULL) { if (COMG(autoreg_verbose) && !compare_function(&results, &value, exists)) { - php_error_docref(NULL, E_WARNING, "Type library constant %s is already defined", ZSTR_VAL(c.name)); + php_error_docref(NULL, E_WARNING, "Type library constant %s is already defined", const_name); } - zend_string_release_ex(c.name, mode & CONST_PERSISTENT); + efree(const_name); ITypeInfo_ReleaseVarDesc(TypeInfo, pVarDesc); continue; } @@ -209,6 +201,8 @@ PHP_COM_DOTNET_API int php_com_import_typelib(ITypeLib *TL, int mode, int codepa if (Z_TYPE(value) == IS_LONG) { ZEND_CONSTANT_SET_FLAGS(&c, mode, 0); ZVAL_LONG(&c.value, Z_LVAL(value)); + c.name = zend_string_init(const_name, len, mode & CONST_PERSISTENT); + efree(const_name); zend_register_constant(&c); } ITypeInfo_ReleaseVarDesc(TypeInfo, pVarDesc);

« previous php.cvs (#104824) next »