Use QStringRef instead of QString whenever possible.

That way we reduce count of temporary QString instances.

Change-Id: Id806c68ea616828c2355c07b8576616fa6a8da17
Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
This commit is contained in:
Jędrzej Nowacki
2014-01-15 16:56:12 +01:00
committed by The Qt Project
parent 15025088ea
commit e485e066ac
11 changed files with 23 additions and 23 deletions

View File

@@ -103,7 +103,7 @@ QString QAndroidMediaStorageLocation::generateFileName(const QString &prefix,
if (lastMediaIndex == 0) {
// first run, find the maximum media number during the fist capture
Q_FOREACH (const QString &fileName, dir.entryList(QStringList() << QString("%1*.%2").arg(prefix).arg(extension))) {
const qint64 mediaIndex = fileName.mid(prefix.length(), fileName.size() - prefix.length() - extension.length() - 1).toInt();
const qint64 mediaIndex = fileName.midRef(prefix.length(), fileName.size() - prefix.length() - extension.length() - 1).toInt();
lastMediaIndex = qMax(lastMediaIndex, mediaIndex);
}
}

View File

@@ -183,7 +183,7 @@ void QAndroidMetaDataReaderControl::updateData()
// The genre can be returned as an ID3v2 id, get the name for it in that case
if (string.startsWith('(') && string.endsWith(')')) {
bool ok = false;
int genreId = string.mid(1, string.length() - 2).toInt(&ok);
int genreId = string.midRef(1, string.length() - 2).toInt(&ok);
if (ok && genreId >= 0 && genreId <= 125)
string = QLatin1String(qt_ID3GenreNames[genreId]);
}

View File

@@ -250,7 +250,7 @@ QString AudioCaptureSession::generateFileName(const QDir &dir,
{
int lastClip = 0;
foreach(QString fileName, dir.entryList(QStringList() << QString("clip_*.%1").arg(ext))) {
int imgNumber = fileName.mid(5, fileName.size()-6-ext.length()).toInt();
int imgNumber = fileName.midRef(5, fileName.size()-6-ext.length()).toInt();
lastClip = qMax(lastClip, imgNumber);
}

View File

@@ -105,7 +105,7 @@ QString AVFStorageLocation::generateFileName(const QString &prefix, const QDir &
if (lastClip == 0) {
//first run, find the maximum clip number during the fist capture
Q_FOREACH (const QString &fileName, dir.entryList(QStringList() << QString("%1*.%2").arg(prefix).arg(ext))) {
int imgNumber = fileName.mid(prefix.length(), fileName.size()-prefix.length()-ext.length()-1).toInt();
int imgNumber = fileName.midRef(prefix.length(), fileName.size()-prefix.length()-ext.length()-1).toInt();
lastClip = qMax(lastClip, imgNumber);
}
}

View File

@@ -508,7 +508,7 @@ QString CameraBinSession::generateFileName(const QString &prefix, const QDir &di
{
int lastClip = 0;
foreach(QString fileName, dir.entryList(QStringList() << QString("%1*.%2").arg(prefix).arg(ext))) {
int imgNumber = fileName.mid(prefix.length(), fileName.size()-prefix.length()-ext.length()-1).toInt();
int imgNumber = fileName.midRef(prefix.length(), fileName.size()-prefix.length()-ext.length()-1).toInt();
lastClip = qMax(lastClip, imgNumber);
}

View File

@@ -83,7 +83,7 @@ int QGstreamerImageCaptureControl::capture(const QString &fileName)
int lastImage = 0;
QDir outputDir = QDir::currentPath();
foreach(QString fileName, outputDir.entryList(QStringList() << "img_*.jpg")) {
int imgNumber = fileName.mid(4, fileName.size()-8).toInt();
int imgNumber = fileName.midRef(4, fileName.size()-8).toInt();
lastImage = qMax(lastImage, imgNumber);
}

View File

@@ -361,7 +361,7 @@ QString QGstreamerRecorderControl::generateFileName(const QDir &dir, const QStri
int lastClip = 0;
foreach(QString fileName, dir.entryList(QStringList() << QString("clip_*.%1").arg(ext))) {
int imgNumber = fileName.mid(5, fileName.size()-6-ext.length()).toInt();
int imgNumber = fileName.midRef(5, fileName.size()-6-ext.length()).toInt();
lastClip = qMax(lastClip, imgNumber);
}

View File

@@ -92,7 +92,7 @@ QString BbMediaStorageLocation::generateFileName(const QString &prefix, const QD
if (lastMediaIndex == 0) {
// first run, find the maximum media number during the fist capture
Q_FOREACH (const QString &fileName, dir.entryList(QStringList() << QString("%1*.%2").arg(prefix).arg(extension))) {
const qint64 mediaIndex = fileName.mid(prefix.length(), fileName.size() - prefix.length() - extension.length() - 1).toInt();
const qint64 mediaIndex = fileName.midRef(prefix.length(), fileName.size() - prefix.length() - extension.length() - 1).toInt();
lastMediaIndex = qMax(lastMediaIndex, mediaIndex);
}
}

View File

@@ -587,8 +587,8 @@ void MmRendererMediaPlayerControl::setMmBufferStatus(const QString &bufferStatus
{
const int slashPos = bufferStatus.indexOf('/');
if (slashPos != -1) {
const int fill = bufferStatus.left(slashPos).toInt();
const int capacity = bufferStatus.mid(slashPos + 1).toInt();
const int fill = bufferStatus.leftRef(slashPos).toInt();
const int capacity = bufferStatus.midRef(slashPos + 1).toInt();
if (capacity != 0) {
m_bufferStatus = fill / static_cast<float>(capacity) * 100.0f;
emit bufferStatusChanged(m_bufferStatus);

View File

@@ -97,8 +97,8 @@ bool MmRendererMetaData::parse(const QString &contextName)
const int separatorPos = line.indexOf(separator);
if (separatorPos != -1) {
const QString key = line.left(separatorPos);
const QString value = line.mid(separatorPos + separator.length());
const QStringRef key = line.left(separatorPos);
const QStringRef value = line.mid(separatorPos + separator.length());
if (key == durationKey)
m_duration = value.toLongLong();
@@ -113,15 +113,15 @@ bool MmRendererMetaData::parse(const QString &contextName)
else if (key == pixelHeightKey)
m_pixelHeight = value.toFloat();
else if (key == titleKey)
m_title = value;
m_title = value.toString();
else if (key == seekableKey)
m_seekable = !(value == QLatin1String("0"));
else if (key == artistKey)
m_artist = value;
m_artist = value.toString();
else if (key == commentKey)
m_comment = value;
m_comment = value.toString();
else if (key == genreKey)
m_genre = value;
m_genre = value.toString();
else if (key == yearKey)
m_year = value.toInt();
else if (key == bitRateKey)
@@ -129,7 +129,7 @@ bool MmRendererMetaData::parse(const QString &contextName)
else if (key == sampleKey)
m_sampleRate = value.toInt();
else if (key == albumKey)
m_album = value;
m_album = value.toString();
else if (key == trackKey)
m_track = value.toInt();
}