Skip to content

Commit

Permalink
CLI: Slightly reduce memory allocations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Geod24 authored and dlang-bot committed Feb 8, 2024
1 parent ac78ae1 commit 7118fa6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions source/dub/commandline.d
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,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
Expand Down Expand Up @@ -419,7 +419,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)
Expand Down Expand Up @@ -449,7 +448,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());
Expand Down

0 comments on commit 7118fa6

Please sign in to comment.