Skip to content

Commit

Permalink
used constFirst or first instead of [0]
Browse files Browse the repository at this point in the history
  • Loading branch information
silverqx committed Aug 17, 2022
1 parent e6566fc commit 89a087b
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/orm/basegrammar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ QString BaseGrammar::wrapAliasedValue(const QString &value, const bool prefixAli
if (prefixAlias)
segments[1] = NOSPACE.arg(m_tablePrefix, segments[1]);

return QStringLiteral("%1 as %2").arg(wrap(segments[0]), wrapValue(segments[1]));
return QStringLiteral("%1 as %2").arg(wrap(segments.constFirst()),
wrapValue(segments[1]));
}

QString BaseGrammar::wrapValue(QString value) const
Expand Down
2 changes: 1 addition & 1 deletion src/orm/schema/grammars/postgresschemagrammar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ PostgresSchemaGrammar::compileForeign(const Blueprint &blueprint,

Q_ASSERT(sqlCommands.size() == 1);

auto &sql = sqlCommands[0];
auto &sql = sqlCommands.first();

const auto isDeferrable = command.deferrable.has_value();

Expand Down
2 changes: 1 addition & 1 deletion src/orm/schema/postgresschemabuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ PostgresSchemaBuilder::parseSchemaAndTable(const QString &table) const

// Instead, get a schema from the configuration
if (!schemaConfig.isEmpty())
schema = std::move(schemaConfig[0]);
schema = std::move(schemaConfig.first());
}

// Default schema
Expand Down
2 changes: 1 addition & 1 deletion src/orm/support/configurationoptionsparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ConfigurationOptionsParser::prepareConfigOptions(const QVariant &options) const
for (const auto &value : list) {
const auto option = value.split(EQ_C);

preparedOptions.insert(option[0].trimmed(),
preparedOptions.insert(option.constFirst().trimmed(),
option[1].trimmed());
}

Expand Down
2 changes: 1 addition & 1 deletion tom/src/tom/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ QString Application::getCommandName()
if (arguments.isEmpty())
return {};

return getCommandName(arguments[0], ShowCommandsList);
return getCommandName(arguments.constFirst(), ShowCommandsList);
}

QString Application::getCommandName(const QString &name, CommandNotFound notFound)
Expand Down
7 changes: 4 additions & 3 deletions tom/src/tom/commands/completecommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int CompleteCommand::run() // NOLINT(readability-function-cognitive-complexity)
const auto currentCommandArg = currentCommandSplitted.size() >= 2
? std::make_optional(currentCommandSplitted[1])
: std::nullopt;
const auto tomCommandSize = currentCommandSplitted[0].size();
const auto tomCommandSize = currentCommandSplitted.constFirst().size();
#else
const auto cwordArg = static_cast<QString::size_type>(value(cword_).toLongLong());

Expand Down Expand Up @@ -489,8 +489,9 @@ QString CompleteCommand::getOptionDefaultValue(const QCommandLineOption &option)
// More default values is not supported
Q_ASSERT(defaultValues.size() <= 1);

return defaultValues.isEmpty() ? EMPTY
: TomUtils::defaultValueText(defaultValues[0]);
return defaultValues.isEmpty()
? EMPTY
: TomUtils::defaultValueText(defaultValues.constFirst());
}

QList<QCommandLineOption>
Expand Down
14 changes: 7 additions & 7 deletions tom/src/tom/commands/integratecommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,10 @@ namespace
/*! Paths to the TinyORM tom zsh completion files. */
Q_GLOBAL_STATIC_WITH_ARGS(
QVector<ZshCompletionPathsItem>, TomZshCompletionPaths,
({{(*ZshCompletionsDirPaths)[0],
QString("%1/_tom").arg((*ZshCompletionsDirPaths)[0])},
{(*ZshCompletionsDirPaths)[1],
QString("%1/_tom").arg((*ZshCompletionsDirPaths)[1])}}));
({{ZshCompletionsDirPaths->constFirst(),
QString("%1/_tom").arg(ZshCompletionsDirPaths->constFirst())},
{ZshCompletionsDirPaths->at(1),
QString("%1/_tom").arg(ZshCompletionsDirPaths->at(1))}}));

} // namespace

Expand All @@ -400,7 +400,7 @@ bool IntegrateCommand::writeTomZshCompletionWrapper() const
createZshCompletionFolder();

// And try to write the completion file again
if (writeTomZshCompletion((*TomZshCompletionPaths)[0].filePath))
if (writeTomZshCompletion(TomZshCompletionPaths->constFirst().filePath))
return true;
}

Expand Down Expand Up @@ -471,14 +471,14 @@ bool IntegrateCommand::writeTomZshCompletion(const QString &filepath)
void IntegrateCommand::createZshCompletionFolder()
{
if (QDir(QStringLiteral("/"))
.mkpath((*TomZshCompletionPaths)[0].dirPath)
.mkpath(TomZshCompletionPaths->constFirst().dirPath)
)
return;

throw Exceptions::RuntimeError(
QStringLiteral("Can not create '%1' directory in %2(), please run "
"with sudo.")
.arg((*TomZshCompletionPaths)[0].dirPath, __tiny_func__));
.arg(TomZshCompletionPaths->constFirst().dirPath, __tiny_func__));
}

QStringList IntegrateCommand::getCompletionFilepaths()
Expand Down
2 changes: 1 addition & 1 deletion tom/src/tom/concerns/callscommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ CallsCommands::createCommandLineArguments(
on the current command-line, and as the last thing append passed arguments. */

// Absolute path of the exe name
QStringList newArguments {std::move(currentArguments[0])};
QStringList newArguments {std::move(currentArguments.first())};
// Command name
newArguments << command;

Expand Down
3 changes: 2 additions & 1 deletion tom/src/tom/concerns/guesscommandname.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ GuessCommandName::guessCommandsWithNamespace(const QString &name)

Q_ASSERT(nameSplitted.size() == 2 && commandNameSplitted.size() == 2);

return commandNameSplitted[0].startsWith(nameSplitted[0], Qt::CaseInsensitive) &&
return commandNameSplitted.constFirst().startsWith(nameSplitted.constFirst(),
Qt::CaseInsensitive) &&
commandNameSplitted[1].startsWith(nameSplitted[1], Qt::CaseInsensitive);
})
/* I have to materialize this view because namespacedCommands variable is
Expand Down
6 changes: 3 additions & 3 deletions tom/src/tom/concerns/printsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void PrintsOptions::printOptionDefaultValue(const QCommandLineOption &option) co
if (defaultValues.isEmpty())
io().newLine();
else
io().comment(TomUtils::defaultValueText(defaultValues[0]));
io().comment(TomUtils::defaultValueText(defaultValues.constFirst()));
}

void PrintsOptions::validateOption(const QCommandLineOption &option) const
Expand All @@ -160,12 +160,12 @@ void PrintsOptions::validateOption(const QCommandLineOption &option) const

// One option name was passed
if (optionsSize == 1) {
if (const auto &longOption = optionNames[0]; longOption.size() <= 1)
if (const auto &longOption = optionNames.constFirst(); longOption.size() <= 1)
throw Exceptions::RuntimeError(longOptionTmpl.arg(longOption));
}
// Two option names were passed
else if (optionsSize == 2) {
if (const auto &shortOption = optionNames[0]; shortOption.size() != 1)
if (const auto &shortOption = optionNames.constFirst(); shortOption.size() != 1)
throw Exceptions::RuntimeError(
QStringLiteral("Short option size has to be 1 (option: %1).")
.arg(shortOption));
Expand Down

0 comments on commit 89a087b

Please sign in to comment.