diff options
| author | Christoph M. Becker <cmbecker69@gmx.de> | 2019-02-22 10:18:39 +0100 |
|---|---|---|
| committer | Christoph M. Becker <cmbecker69@gmx.de> | 2019-02-22 10:35:19 +0100 |
| commit | 427ebce6295b296c1f18f6bd927bf3cd295be815 (patch) | |
| tree | 02c33a9524563a9697ba7bc6feee23f3271bb5ed /ext/com_dotnet | |
| parent | a37c92659100e08bbc19cdf4aad3b56e43ef85d4 (diff) | |
| download | php-git-427ebce6295b296c1f18f6bd927bf3cd295be815.tar.gz | |
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.
Diffstat (limited to 'ext/com_dotnet')
| -rw-r--r-- | ext/com_dotnet/com_typeinfo.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/ext/com_dotnet/com_typeinfo.c b/ext/com_dotnet/com_typeinfo.c index 117021337c..517e04ed5c 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); |
