[corefoundation] Fix `CFString.ToString` to cache the result (#11932)

`CFString` cache the native immutable string into it's `str` field and
use it to avoid p/invokes when possible.

`ToString` retrieved the string without setting `str` (if `null`) so it
missed opportunities to avoid the native calls.
This commit is contained in:
Sebastien Pouliot 2021-06-15 09:19:35 -04:00 коммит произвёл GitHub
Родитель 447c59db60
Коммит 7dc918ca34
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 3 добавлений и 3 удалений

Просмотреть файл

@ -217,9 +217,9 @@ namespace CoreFoundation {
public override string ToString () public override string ToString ()
{ {
if (str != null) if (str is null)
return str; str = FromHandle (Handle);
return FromHandle (Handle); return str;
} }
#endif // !COREBUILD #endif // !COREBUILD
} }