From 75dfd67ba310cf11f6eb841aa75625a5337eea1e Mon Sep 17 00:00:00 2001 From: Mathias Lang Date: Wed, 7 Feb 2024 19:43:38 +0100 Subject: [PATCH] CLI: Slightly reduce memory allocations By improving commandNames to only allocate once (the array call) instead of many times (once per CommandGroup + join call), as well as removing a call to commandNames and using a simple getter. --- source/dub/commandline.d | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 954a7ea7e..70e721a21 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -139,7 +139,7 @@ struct CommandLineHandler */ string[] commandNames() { - return commandGroups.map!(g => g.commands.map!(c => c.name).array).join; + return commandGroups.map!(g => g.commands).joiner.map!(c => c.name).array; } /** Parses the general options and sets up the log level @@ -405,7 +405,6 @@ int runDubCommandLine(string[] args) } auto handler = CommandLineHandler(getCommands()); - auto commandNames = handler.commandNames(); // Special syntaxes need to be handled before regular argument parsing if (args.length >= 2) @@ -435,7 +434,7 @@ int runDubCommandLine(string[] args) // We have to assume it isn't, and to reduce the risk of false positive // we only consider the case where the file name is the first argument, // as the shell invocation cannot be controlled. - else if (!commandNames.canFind(args[1]) && !args[1].startsWith("-")) { + else if (handler.getCommand(args[1]) is null && !args[1].startsWith("-")) { if (exists(args[1])) { auto path = getTempFile("app", ".d"); copy(args[1], path.toNativeString());