Skip to content

Commit 7118fa6

Browse files
Geod24dlang-bot
authored andcommitted
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.
1 parent ac78ae1 commit 7118fa6

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

source/dub/commandline.d

+2-3
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ struct CommandLineHandler
153153
*/
154154
string[] commandNames()
155155
{
156-
return commandGroups.map!(g => g.commands.map!(c => c.name).array).join;
156+
return commandGroups.map!(g => g.commands).joiner.map!(c => c.name).array;
157157
}
158158

159159
/** Parses the general options and sets up the log level
@@ -419,7 +419,6 @@ int runDubCommandLine(string[] args)
419419
}
420420

421421
auto handler = CommandLineHandler(getCommands());
422-
auto commandNames = handler.commandNames();
423422

424423
// Special syntaxes need to be handled before regular argument parsing
425424
if (args.length >= 2)
@@ -449,7 +448,7 @@ int runDubCommandLine(string[] args)
449448
// We have to assume it isn't, and to reduce the risk of false positive
450449
// we only consider the case where the file name is the first argument,
451450
// as the shell invocation cannot be controlled.
452-
else if (!commandNames.canFind(args[1]) && !args[1].startsWith("-")) {
451+
else if (handler.getCommand(args[1]) is null && !args[1].startsWith("-")) {
453452
if (exists(args[1])) {
454453
auto path = getTempFile("app", ".d");
455454
copy(args[1], path.toNativeString());

0 commit comments

Comments
 (0)