From f15676d0a16839a616166b494591830a3968216a Mon Sep 17 00:00:00 2001 From: morkt Date: Tue, 29 Jul 2014 15:30:23 +0400 Subject: [PATCH] (TryOpen): use lazy evaluation for filename extension check. --- GameRes/ArcFile.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/GameRes/ArcFile.cs b/GameRes/ArcFile.cs index 1c1bd98f..f15eea8f 100644 --- a/GameRes/ArcFile.cs +++ b/GameRes/ArcFile.cs @@ -64,8 +64,8 @@ namespace GameRes /// public static ArcFile TryOpen (string filename) { + var ext = new Lazy (() => Path.GetExtension (filename).TrimStart ('.').ToLower()); var file = new ArcView (filename); - string ext = Path.GetExtension (filename).TrimStart ('.').ToLower(); try { uint signature = file.View.ReadUInt32 (0); @@ -73,7 +73,9 @@ namespace GameRes { var range = FormatCatalog.Instance.LookupSignature (signature); // check formats that match filename extension first - foreach (var impl in range.OrderByDescending (f => f.Extensions.First() == ext)) + if (range.Skip(1).Any()) // if range.Count() > 1 + range = range.OrderByDescending (f => f.Extensions.First() == ext.Value); + foreach (var impl in range) { try {