Skip to content

Commit

Permalink
Performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
LordJZ committed Oct 11, 2017
1 parent e5b7d1d commit d4cb45f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/WebCompiler/Config/ConfigFileProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ConfigFileProcessor
/// <param name="configs">Optional configuration items in the config file</param>
/// <param name="force">Forces compilation of all config items.</param>
/// <returns>A list of compiler results.</returns>
public IEnumerable<CompilerResult> Process(string configFile, IEnumerable<Config> configs = null, bool force = false)
public IEnumerable<CompilerResult> Process(string configFile, Config[] configs = null, bool force = false)
{
if (_processing.Contains(configFile))
return Enumerable.Empty<CompilerResult>();
Expand All @@ -36,8 +36,8 @@ public IEnumerable<CompilerResult> Process(string configFile, IEnumerable<Config
string directory = info.Directory.FullName;
configs = configs ?? ConfigHandler.GetConfigs(configFile);

if (configs.Any())
OnConfigProcessed(configs.First(), 0, configs.Count());
if (configs.Length > 0)
OnConfigProcessed(configs.First(), 0, configs.Length);

int i = 0;
foreach (Config config in configs)
Expand All @@ -56,7 +56,7 @@ public IEnumerable<CompilerResult> Process(string configFile, IEnumerable<Config
list.Add(ProcessConfig(directory, config));
}

OnConfigProcessed(config, i, configs.Count());
OnConfigProcessed(config, i, configs.Length);
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/WebCompiler/Config/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,15 @@ public void CreateDefaultsFile(string fileName)
/// </summary>
/// <param name="fileName">A relative or absolute file path to the configuration file.</param>
/// <returns>A list of Config objects.</returns>
public static IEnumerable<Config> GetConfigs(string fileName)
public static Config[] GetConfigs(string fileName)
{
FileInfo file = new FileInfo(fileName);

if (!file.Exists)
return Enumerable.Empty<Config>();
return new Config[0];

string content = File.ReadAllText(fileName);
var configs = JsonConvert.DeserializeObject<IEnumerable<Config>>(content);
string folder = Path.GetDirectoryName(file.FullName);
Config[] configs = JsonConvert.DeserializeObject<Config[]>(content);

foreach (Config config in configs)
{
Expand Down
6 changes: 3 additions & 3 deletions src/WebCompiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static void EventHookups(ConfigFileProcessor processor, string configPat
FileMinifier.AfterWritingGzipFile += (s, e) => { Console.WriteLine($" \x1B[32mGZipped"); };
}

private static IEnumerable<Config> GetConfigs(string configPath, string file)
private static Config[] GetConfigs(string configPath, string file)
{
var configs = ConfigHandler.GetConfigs(configPath);

Expand All @@ -60,9 +60,9 @@ private static IEnumerable<Config> GetConfigs(string configPath, string file)
if (file != null)
{
if (file.StartsWith("*"))
configs = configs.Where(c => Path.GetExtension(c.InputFile).Equals(file.Substring(1), StringComparison.OrdinalIgnoreCase));
configs = configs.Where(c => Path.GetExtension(c.InputFile).Equals(file.Substring(1), StringComparison.OrdinalIgnoreCase)).ToArray();
else
configs = configs.Where(c => c.InputFile.Equals(file, StringComparison.OrdinalIgnoreCase));
configs = configs.Where(c => c.InputFile.Equals(file, StringComparison.OrdinalIgnoreCase)).ToArray();
}

return configs;
Expand Down
4 changes: 1 addition & 3 deletions src/WebCompilerTest/Config/ConfigHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ public void AddConfig()
[TestMethod, TestCategory("Config")]
public void NonExistingConfigFileShouldReturnEmptyList()
{
var expectedResult = Enumerable.Empty<WebCompiler.Config>();

var result = ConfigHandler.GetConfigs("../NonExistingFile.config");

Assert.AreEqual(expectedResult, result);
Assert.AreEqual(0, result.Length);
}
}
}
1 change: 1 addition & 0 deletions src/WebCompilerTest/Minify/artifacts/css/minify.less
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
body {
background: black
}
2 changes: 1 addition & 1 deletion src/WebCompilerVsix/CompilerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static void ConfigProcessed(object sender, ConfigProcessedEventArgs e)
_dte.StatusBar.Progress(true, "Compiling...", e.AmountProcessed, e.Total);
}

public static void Process(string configFile, IEnumerable<Config> configs = null, bool force = false)
public static void Process(string configFile, Config[] configs = null, bool force = false)
{
ThreadPool.QueueUserWorkItem((o) =>
{
Expand Down

0 comments on commit d4cb45f

Please sign in to comment.