Repository: microsoft/PowerToys
File: src/modules/launcher/Wox.Plugin/Common/ShellLocalization.cs (C#)

Code before:

        /// <summary>
        /// Returns the localized name of a shell item.
        /// </summary>
        /// <param name="path">Path to the shell item (e. g. shortcut 'File Explorer.lnk').</param>
        /// <returns>The localized name as string or <see cref="string.Empty"/>.</returns>
        public string GetLocalizedName(string path)
        {
            string lowerInvariantPath = path.ToLowerInvariant();

            // Checking cache if path is already localized
            if (_localizationCache.TryGetValue(lowerInvariantPath, out string value))
            {
                return value;
            }

            Guid shellItemType = ShellItemTypeConstants.ShellItemGuid;
            int retCode = NativeMethods.SHCreateItemFromParsingName(path, IntPtr.Zero, ref shellItemType, out IShellItem shellItem);
            if (retCode != 0)
            {
                return string.Empty;
            }

            shellItem.GetDisplayName(SIGDN.NORMALDISPLAY, out string filename);

            _localizationCache.TryAdd(lowerInvariantPath, filename);

            return filename;
        }

        /// <summary>
        /// This method returns the localized path to a shell item (folder or file)
        /// </summary>
        /// <param name="path">The path to localize</param>
        /// <returns>The localized path or the original path if localized version is not available</returns>
        public string GetLocalizedPath(string path)
        {
            path = Environment.ExpandEnvironmentVariables(path);
            string ext = Path.GetExtension(path);
            var pathParts = path.Split("\\");
            string[] locPath = new string[pathParts.Length];

            for (int i = 0; i < pathParts.Length; i++)
            {
                if (i == 0 && pathParts[i].EndsWith(':'))
                {
                    // Skip the drive letter.
                    locPath[0] = pathParts[0];
                    continue;
                }


Review comment (performance):
Shouldn't it be the following?


```suggestion
            _ = _localizationCache.TryAdd(lowerInvariantPath, filename);
```


Code after:

        /// <summary>
        /// Returns the localized name of a shell item.
        /// </summary>
        /// <param name="path">Path to the shell item (e. g. shortcut 'File Explorer.lnk').</param>
        /// <returns>The localized name as string or <see cref="string.Empty"/>.</returns>
        public string GetLocalizedName(string path)
        {
            string lowerInvariantPath = path.ToLowerInvariant();

            // Checking cache if path is already localized
            if (_localizationCache.TryGetValue(lowerInvariantPath, out string value))
            {
                return value;
            }

            Guid shellItemType = ShellItemTypeConstants.ShellItemGuid;
            int retCode = NativeMethods.SHCreateItemFromParsingName(path, IntPtr.Zero, ref shellItemType, out IShellItem shellItem);
            if (retCode != 0)
            {
                return string.Empty;
            }

            shellItem.GetDisplayName(SIGDN.NORMALDISPLAY, out string filename);

            _ = _localizationCache.TryAdd(lowerInvariantPath, filename);

            return filename;
        }

        /// <summary>
        /// This method returns the localized path to a shell item (folder or file)
        /// </summary>
        /// <param name="path">The path to localize</param>
        /// <returns>The localized path or the original path if localized version is not available</returns>
        public string GetLocalizedPath(string path)
        {
            path = Environment.ExpandEnvironmentVariables(path);
            string ext = Path.GetExtension(path);
            var pathParts = path.Split("\\");
            string[] locPath = new string[pathParts.Length];

            for (int i = 0; i < pathParts.Length; i++)
            {
                if (i == 0 && pathParts[i].EndsWith(':'))
                {
                    // Skip the drive letter.
                    locPath[0] = pathParts[0];
                    continue;
                }