QString: reduce template bloat

Reduce the number of (non-regex) splitString instantiations from
six to two by:

- Passing separators by (const QChar*, int) and using qFindString()
  instead of indexOf()
- Passing QString as QStringRef when the output is QVector<QStringRef>.
  Doing so also allows to drop the MidMethod template parameter since
  QString::midRef() is no longer being used.

(Somewhat disappointing) effects on Linux GCC 4.9 stripped release builds:
 text   -500B
 data    +-0B
 relocs  +-0

Change-Id: Id89e2814d5f7da5170181d863167517943c2e0cd
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2015-01-25 03:27:26 +01:00
parent 131b3cffc8
commit 72c456909c

View File

@ -6575,24 +6575,25 @@ QString QString::number(double n, char f, int prec)
}
namespace {
template<class ResultList, class StringSource, typename MidMethod, typename Separtor>
static ResultList splitString(const StringSource &source, MidMethod mid, const Separtor &sep,
template<class ResultList, class StringSource>
static ResultList splitString(const StringSource &source, const QChar *sep,
QString::SplitBehavior behavior, Qt::CaseSensitivity cs, const int separatorSize)
{
ResultList list;
int start = 0;
int end;
int extra = 0;
while ((end = source.indexOf(sep, start + extra, cs)) != -1) {
while ((end = qFindString(source.constData(), source.size(), start + extra, sep, separatorSize, cs)) != -1) {
if (start != end || behavior == QString::KeepEmptyParts)
list.append((source.*mid)(start, end - start));
list.append(source.mid(start, end - start));
start = end + separatorSize;
extra = (separatorSize == 0 ? 1 : 0);
}
if (start != source.size() || behavior == QString::KeepEmptyParts)
list.append((source.*mid)(start, -1));
list.append(source.mid(start, -1));
return list;
}
} // namespace
/*!
@ -6615,7 +6616,7 @@ static ResultList splitString(const StringSource &source, MidMethod mid, const S
*/
QStringList QString::split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
{
return splitString<QStringList>(*this, &QString::mid, sep, behavior, cs, sep.size());
return splitString<QStringList>(*this, sep.constData(), behavior, cs, sep.size());
}
/*!
@ -6638,14 +6639,14 @@ QStringList QString::split(const QString &sep, SplitBehavior behavior, Qt::CaseS
*/
QVector<QStringRef> QString::splitRef(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
{
return splitString<QVector<QStringRef> >(*this, &QString::midRef, sep, behavior, cs, sep.size());
return splitString<QVector<QStringRef> >(QStringRef(this), sep.constData(), behavior, cs, sep.size());
}
/*!
\overload
*/
QStringList QString::split(QChar sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
{
return splitString<QStringList>(*this, &QString::mid, sep, behavior, cs, 1);
return splitString<QStringList>(*this, &sep, behavior, cs, 1);
}
/*!
@ -6654,7 +6655,7 @@ QStringList QString::split(QChar sep, SplitBehavior behavior, Qt::CaseSensitivit
*/
QVector<QStringRef> QString::splitRef(QChar sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
{
return splitString<QVector<QStringRef> >(*this, &QString::midRef, sep, behavior, cs, 1);
return splitString<QVector<QStringRef> >(QStringRef(this), &sep, behavior, cs, 1);
}
/*!
@ -6676,7 +6677,7 @@ QVector<QStringRef> QString::splitRef(QChar sep, SplitBehavior behavior, Qt::Cas
*/
QVector<QStringRef> QStringRef::split(const QString &sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const
{
return splitString<QVector<QStringRef> >(*this, &QStringRef::mid, sep, behavior, cs, sep.size());
return splitString<QVector<QStringRef> >(*this, sep.constData(), behavior, cs, sep.size());
}
/*!
@ -6685,7 +6686,7 @@ QVector<QStringRef> QStringRef::split(const QString &sep, QString::SplitBehavior
*/
QVector<QStringRef> QStringRef::split(QChar sep, QString::SplitBehavior behavior, Qt::CaseSensitivity cs) const
{
return splitString<QVector<QStringRef> >(*this, &QStringRef::mid, sep, behavior, cs, 1);
return splitString<QVector<QStringRef> >(*this, &sep, behavior, cs, 1);
}
#ifndef QT_NO_REGEXP