Utils: Remove std::initializer_list contructor

If you write

Utils::SmallStringView view;
Utils::SmallString text{view};

it selects the std::initializer_list contructor. Not the didicated
constructore. It is much to easy to get it wrong so it is better
to make it explicit.

Change-Id: I4240eaf1f39cf71d37df4480fea1ecfa3ea83cb0
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Marco Bubke
2021-05-19 18:50:51 +02:00
parent 7b330d3496
commit 8603eb5ba9
15 changed files with 52 additions and 57 deletions

View File

@@ -219,7 +219,7 @@ public:
});
for (const CompilerMacro &macro : macros)
commandLine.emplace_back(Utils::SmallString{"-D", macro.key, "=", macro.value});
commandLine.emplace_back(Utils::SmallString::join({"-D", macro.key, "=", macro.value}));
}
void addPreIncludeSearchPath(NativeFilePathView preIncludeSearchPath)

View File

@@ -90,8 +90,8 @@ public:
}
FilePath(Utils::SmallStringView directory, Utils::SmallStringView name)
: Utils::PathString({directory, "/", name}),
m_slashIndex(std::ptrdiff_t(directory.size()))
: Utils::PathString(Utils::PathString::join({directory, "/", name}))
, m_slashIndex(std::ptrdiff_t(directory.size()))
{}
bool isValid() const { return size() > 0 && m_slashIndex >= 0; }

View File

@@ -83,8 +83,9 @@ public:
}
NativeFilePath(Utils::SmallStringView directory, Utils::SmallStringView name)
: m_path({directory, Utils::HostOsInfo::isWindowsHost() ? "\\" : "/", name}),
m_slashIndex(directory.size())
: m_path(Utils::PathString::join(
{directory, Utils::HostOsInfo::isWindowsHost() ? "\\" : "/", name}))
, m_slashIndex(directory.size())
{}
Utils::SmallStringView directory() const noexcept

View File

@@ -248,9 +248,8 @@ void CreateTableSqlStatementBuilder::bindColumnDefinitionsAndTableConstraints()
columnDefinitionStrings.reserve(m_columns.size());
for (const Column &column : m_columns) {
Utils::SmallString columnDefinitionString = {column.name,
SqlStatementBuilder::columnTypeToString(
column.type)};
auto columnDefinitionString = Utils::SmallString::join(
{column.name, SqlStatementBuilder::columnTypeToString(column.type)});
ContraintsVisiter visiter{columnDefinitionString};

View File

@@ -129,7 +129,7 @@ sqlite3 *DatabaseBackend::sqliteDatabaseHandle() const
void DatabaseBackend::setPragmaValue(Utils::SmallStringView pragmaKey, Utils::SmallStringView newPragmaValue)
{
ReadWriteStatement<1>{Utils::SmallString{"PRAGMA ", pragmaKey, "='", newPragmaValue, "'"},
ReadWriteStatement<1>{Utils::SmallString::join({"PRAGMA ", pragmaKey, "='", newPragmaValue, "'"}),
m_database}
.execute();
Utils::SmallString pragmeValueInDatabase = toValue<Utils::SmallString>("PRAGMA " + pragmaKey);

View File

@@ -57,7 +57,7 @@ public:
checkTableName();
checkColumns();
return {"CREATE ",
return Utils::SmallString::join({"CREATE ",
m_indexType == IndexType::Unique ? "UNIQUE " : "",
"INDEX IF NOT EXISTS index_",
m_tableName,
@@ -67,8 +67,7 @@ public:
m_tableName,
"(",
m_columnNames.join(", "),
")"
};
")"});
}
void checkTableName() const

View File

@@ -127,9 +127,9 @@ void Internal::SessionsBase::createSessionTable(Database &database)
void Sessions::revert()
{
ReadStatement<1> selectChangeSets{Utils::PathString{"SELECT changeset FROM ",
ReadStatement<1> selectChangeSets{Utils::PathString::join({"SELECT changeset FROM ",
sessionsTableName,
" ORDER BY id DESC"},
" ORDER BY id DESC"}),
database};
auto changeSets = selectChangeSets.values<SessionChangeSet>(1024);
@@ -151,9 +151,9 @@ void Sessions::revert()
void Sessions::apply()
{
ReadStatement<1> selectChangeSets{Utils::PathString{"SELECT changeset FROM ",
ReadStatement<1> selectChangeSets{Utils::PathString::join({"SELECT changeset FROM ",
sessionsTableName,
" ORDER BY id"},
" ORDER BY id"}),
database};
auto changeSets = selectChangeSets.values<SessionChangeSet>(1024);
@@ -182,14 +182,14 @@ void Sessions::applyAndUpdateSessions()
void Sessions::deleteAll()
{
WriteStatement{Utils::SmallString{"DELETE FROM ", sessionsTableName}, database}.execute();
WriteStatement{Utils::SmallString::join({"DELETE FROM ", sessionsTableName}), database}.execute();
}
SessionChangeSets Sessions::changeSets() const
{
ReadStatement<1> selectChangeSets{Utils::PathString{"SELECT changeset FROM ",
ReadStatement<1> selectChangeSets{Utils::PathString::join({"SELECT changeset FROM ",
sessionsTableName,
" ORDER BY id DESC"},
" ORDER BY id DESC"}),
database};
return selectChangeSets.values<SessionChangeSet>(1024);

View File

@@ -62,9 +62,8 @@ public:
Utils::SmallStringView sessionsTableName)
: SessionsBase(database, sessionsTableName)
, database(database)
, insertSession{Utils::PathString{"INSERT INTO ",
sessionsTableName,
"(changeset) VALUES(?)"},
, insertSession{Utils::PathString::join(
{"INSERT INTO ", sessionsTableName, "(changeset) VALUES(?)"}),
database}
, databaseName(databaseName)
, session{nullptr, sqlite3session_delete}

View File

@@ -152,14 +152,7 @@ public:
>
BasicSmallString(BeginIterator begin, EndIterator end)
: BasicSmallString(&(*begin), size_type(end - begin))
{
}
BasicSmallString(std::initializer_list<SmallStringView> list)
: m_data(Internal::StringDataLayout<Size>())
{
appendInitializerList(list, 0);
}
{}
~BasicSmallString() noexcept
{

View File

@@ -75,7 +75,8 @@ void AsynchronousImageCache::request(Utils::SmallStringView name,
ImageCacheGeneratorInterface &generator,
TimeStampProviderInterface &timeStampProvider)
{
const auto id = extraId.empty() ? Utils::PathString{name} : Utils::PathString{name, "+", extraId};
const auto id = extraId.empty() ? Utils::PathString{name}
: Utils::PathString::join({name, "+", extraId});
const auto timeStamp = timeStampProvider.timeStamp(name);
const auto entry = requestType == RequestType::Image ? storage.fetchImage(id, timeStamp)

View File

@@ -81,7 +81,7 @@ void ImageCacheGenerator::generateImage(Utils::SmallStringView name,
namespace {
Utils::PathString createId(Utils::SmallStringView name, Utils::SmallStringView extraId)
{
return extraId.empty() ? Utils::PathString{name} : Utils::PathString{name, "+", extraId};
return extraId.empty() ? Utils::PathString{name} : Utils::PathString::join({name, "+", extraId});
}
template<typename Callbacks, typename... Argument>
void callCallbacks(const Callbacks &callbacks, Argument &&...arguments)

View File

@@ -37,7 +37,8 @@ namespace {
Utils::PathString createId(Utils::PathString filePath, Utils::SmallString extraId)
{
return extraId.empty() ? Utils::PathString{filePath} : Utils::PathString{filePath, "+", extraId};
return extraId.empty() ? Utils::PathString{filePath}
: Utils::PathString::join({filePath, "+", extraId});
}
} // namespace

View File

@@ -83,7 +83,7 @@ public:
}
SourcePath(Utils::SmallStringView directory, Utils::SmallStringView name)
: Utils::PathString({directory, "/", name})
: Utils::PathString(Utils::PathString::join({directory, "/", name}))
, m_slashIndex(std::ptrdiff_t(directory.size()))
{}

View File

@@ -92,10 +92,12 @@ FilePath PchCreator::generatePchFilePath() const
std::uniform_int_distribution<std::uint_fast64_t> distribution(
1, std::numeric_limits<std::uint_fast64_t>::max());
return FilePathView{Utils::PathString{Utils::SmallString(m_environment.pchBuildDirectory()),
auto joinedPath = Utils::PathString::join({Utils::SmallString(m_environment.pchBuildDirectory()),
"/",
std::to_string(distribution(randomNumberGenator)),
".pch"}};
".pch"});
return FilePathView{joinedPath};
}
Utils::SmallStringVector PchCreator::generateClangCompilerArguments(const PchTask &pchTask,

View File

@@ -1556,7 +1556,7 @@ TEST(SmallString, CompareTextWithDifferentLineEndings)
TEST(SmallString, ConstSubscriptOperator)
{
const SmallString text = {"some text"};
const SmallString text{"some text"};
auto &&sign = text[5];
@@ -1565,7 +1565,7 @@ TEST(SmallString, ConstSubscriptOperator)
TEST(SmallString, NonConstSubscriptOperator)
{
SmallString text = {"some text"};
SmallString text{"some text"};
auto &&sign = text[5];
@@ -1574,7 +1574,7 @@ TEST(SmallString, NonConstSubscriptOperator)
TEST(SmallString, ManipulateConstSubscriptOperator)
{
const SmallString text = {"some text"};
const SmallString text{"some text"};
auto &&sign = text[5];
sign = 'q';
@@ -1609,28 +1609,28 @@ TEST(SmallString, EmptyInitializerListSize)
TEST(SmallString, EmptyInitializerListNullTerminated)
{
auto end = SmallString{{}}[0];
auto end = SmallString::join({})[0];
ASSERT_THAT(end, '\0');
}
TEST(SmallString, InitializerListContent)
{
SmallString text = {"some", " ", "text"};
auto text = SmallString::join({"some", " ", "text"});
ASSERT_THAT(text, SmallString("some text"));
}
TEST(SmallString, InitializerListSize)
{
SmallString text = {"some", " ", "text"};
auto text = SmallString::join({"some", " ", "text"});
ASSERT_THAT(text, SizeIs(9));
}
TEST(SmallString, InitializerListNullTerminated)
{
auto end = SmallString{"some", " ", "text"}[9];
auto end = SmallString::join({"some", " ", "text"})[9];
ASSERT_THAT(end, '\0');
}