Skip to content

Commit 039bbb7

Browse files
committed
Slight optimizations for the previous commit
1 parent f7f5228 commit 039bbb7

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ public bool MatchesExtension( string extension, bool extensionMayHaveMultipleSuf
102102
for( int i = 0; i < extensions.Length; i++ )
103103
{
104104
if( extension.EndsWith( extensions[i], StringComparison.Ordinal ) )
105+
{
106+
extensionsSet.Add( extension );
105107
return true;
108+
}
106109
}
107110
}
108111

@@ -358,7 +361,7 @@ private static FileBrowser Instance
358361
[SerializeField]
359362
private FiletypeIcon[] filetypeIcons;
360363

361-
private Dictionary<string, Sprite> filetypeToIcon;
364+
private readonly Dictionary<string, Sprite> filetypeToIcon = new Dictionary<string, Sprite>( 128 );
362365

363366
[SerializeField]
364367
internal Sprite multiSelectionToggleOffIcon;
@@ -913,7 +916,7 @@ void IListViewAdapter.SetItemContent( ListItem item )
913916
#region Initialization Functions
914917
private void InitializeFiletypeIcons()
915918
{
916-
filetypeToIcon = new Dictionary<string, Sprite>();
919+
filetypeToIcon.Clear();
917920
allIconExtensionsHaveSingleSuffix = true;
918921

919922
for( int i = 0; i < filetypeIcons.Length; i++ )
@@ -1797,7 +1800,10 @@ public void RefreshFiles( bool pathChanged )
17971800
for( int j = 0; j < excludedExtensions.Length; j++ )
17981801
{
17991802
if( extension.EndsWith( excludedExtensions[j], StringComparison.Ordinal ) )
1803+
{
1804+
excludedExtensionsSet.Add( extension );
18001805
continue;
1806+
}
18011807
}
18021808
}
18031809

@@ -2209,10 +2215,14 @@ internal Sprite GetIconForFileEntry( FileSystemEntry fileInfo )
22092215
for( int i = 0; i < filetypeIcons.Length; i++ )
22102216
{
22112217
if( fileInfo.Extension.EndsWith( filetypeIcons[i].extension, StringComparison.Ordinal ) )
2218+
{
2219+
filetypeToIcon[fileInfo.Extension] = filetypeIcons[i].icon;
22122220
return filetypeIcons[i].icon;
2221+
}
22132222
}
22142223
}
22152224

2225+
filetypeToIcon[fileInfo.Extension] = defaultIcon;
22162226
return defaultIcon;
22172227
}
22182228

0 commit comments

Comments
 (0)