forked from qt-creator/qt-creator
QtVersionNumber: Make it smaller and faster
This yields 1% speedup on total startup with -noload Welcome Change-Id: Ib3f1e45032c4a2dbe21ae86a1df65d118f89cba1 Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
@@ -76,15 +76,9 @@ QtVersionNumber::QtVersionNumber(int ma, int mi, int p)
|
|||||||
|
|
||||||
QtVersionNumber::QtVersionNumber(const QString &versionString)
|
QtVersionNumber::QtVersionNumber(const QString &versionString)
|
||||||
{
|
{
|
||||||
if (!checkVersionString(versionString)) {
|
if (::sscanf(versionString.toLatin1().constData(), "%d.%d.%d",
|
||||||
|
&majorVersion, &minorVersion, &patchVersion) != 3)
|
||||||
majorVersion = minorVersion = patchVersion = -1;
|
majorVersion = minorVersion = patchVersion = -1;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList parts = versionString.split(QLatin1Char('.'));
|
|
||||||
majorVersion = parts.at(0).toInt();
|
|
||||||
minorVersion = parts.at(1).toInt();
|
|
||||||
patchVersion = parts.at(2).toInt();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QtVersionNumber::QtVersionNumber()
|
QtVersionNumber::QtVersionNumber()
|
||||||
@@ -92,34 +86,13 @@ QtVersionNumber::QtVersionNumber()
|
|||||||
majorVersion = minorVersion = patchVersion = -1;
|
majorVersion = minorVersion = patchVersion = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QtVersionNumber::checkVersionString(const QString &version) const
|
|
||||||
{
|
|
||||||
int dots = 0;
|
|
||||||
const QString validChars = QLatin1String("0123456789.");
|
|
||||||
foreach (const QChar &c, version) {
|
|
||||||
if (!validChars.contains(c))
|
|
||||||
return false;
|
|
||||||
if (c == QLatin1Char('.'))
|
|
||||||
++dots;
|
|
||||||
}
|
|
||||||
if (dots != 2)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QtVersionNumber::operator <(const QtVersionNumber &b) const
|
bool QtVersionNumber::operator <(const QtVersionNumber &b) const
|
||||||
{
|
{
|
||||||
if (majorVersion < b.majorVersion)
|
if (majorVersion != b.majorVersion)
|
||||||
return true;
|
return majorVersion < b.majorVersion;
|
||||||
if (majorVersion > b.majorVersion)
|
if (minorVersion != b.minorVersion)
|
||||||
return false;
|
return minorVersion < b.minorVersion;
|
||||||
if (minorVersion < b.minorVersion)
|
return patchVersion < b.patchVersion;
|
||||||
return true;
|
|
||||||
if (minorVersion > b.minorVersion)
|
|
||||||
return false;
|
|
||||||
if (patchVersion < b.patchVersion)
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QtVersionNumber::operator >(const QtVersionNumber &b) const
|
bool QtVersionNumber::operator >(const QtVersionNumber &b) const
|
||||||
|
@@ -79,8 +79,6 @@ public:
|
|||||||
bool operator >=(const QtVersionNumber &b) const;
|
bool operator >=(const QtVersionNumber &b) const;
|
||||||
bool operator !=(const QtVersionNumber &b) const;
|
bool operator !=(const QtVersionNumber &b) const;
|
||||||
bool operator ==(const QtVersionNumber &b) const;
|
bool operator ==(const QtVersionNumber &b) const;
|
||||||
private:
|
|
||||||
bool checkVersionString(const QString &version) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Internal { class QtOptionsPageWidget; }
|
namespace Internal { class QtOptionsPageWidget; }
|
||||||
|
Reference in New Issue
Block a user