summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorhjk <qthjk@ovi.com>2012-06-27 13:15:07 +0200
committerQt by Nokia <qt-info@nokia.com>2012-08-05 07:25:43 +0200
commit702788f4adef6c4dbc3144083c515a60274a3164 (patch)
treef31d367ccad87280730004274eede85b7470d460 /src/corelib/tools
parentb7db596590ff0cc31c56338684970d835840fdaa (diff)
qdatetime: micro optimization in fmtDateTime
The function showed up in the profiler when doing heavy logging involving timestamps in Qt Creator. Change-Id: I81c4e22981a5de91df3da6a0f1df2a08552fa71a Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qdatetime.cpp72
1 files changed, 36 insertions, 36 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index 4c3baa30ce..b9311df807 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -3817,59 +3817,59 @@ static QString getFmtString(const QString& f, const QTime* dt = 0, const QDate*
// Parses the format string and uses getFmtString to get the values for the tokens. Ret
static QString fmtDateTime(const QString& f, const QTime* dt, const QDate* dd)
{
- const QLatin1Char quote('\'');
+ QString buf;
+
if (f.isEmpty())
- return QString();
+ return buf;
if (dt && !dt->isValid())
- return QString();
+ return buf;
if (dd && !dd->isValid())
- return QString();
+ return buf;
const bool ap = hasUnquotedAP(f);
- QString buf;
QString frm;
- QChar status(QLatin1Char('0'));
-
- for (int i = 0; i < (int)f.length(); ++i) {
- if (f.at(i) == quote) {
- if (status == quote) {
- if (i > 0 && f.at(i - 1) == quote)
- buf += QLatin1Char('\'');
- status = QLatin1Char('0');
+ uint status = '0';
+
+ for (int i = 0, n = f.length(); i < n; ++i) {
+ const QChar c = f.at(i);
+ const uint cc = c.unicode();
+ if (cc == '\'') {
+ if (status == cc) {
+ if (i > 0 && f.at(i - 1).unicode() == cc)
+ buf += c;
+ status = '0';
} else {
if (!frm.isEmpty()) {
buf += getFmtString(frm, dt, dd, ap);
frm.clear();
}
- status = quote;
+ status = cc;
}
- } else if (status == quote) {
- buf += f.at(i);
- } else if (f.at(i) == status) {
- if ((ap) && ((f.at(i) == QLatin1Char('P')) || (f.at(i) == QLatin1Char('p'))))
- status = QLatin1Char('0');
- frm += f.at(i);
+ } else if (status == '\'') {
+ buf += c;
+ } else if (c == status) {
+ if (ap && (cc == 'P' || cc == 'p'))
+ status = '0';
+ frm += c;
} else {
buf += getFmtString(frm, dt, dd, ap);
frm.clear();
- if ((f.at(i) == QLatin1Char('h')) || (f.at(i) == QLatin1Char('m'))
- || (f.at(i) == QLatin1Char('H'))
- || (f.at(i) == QLatin1Char('s')) || (f.at(i) == QLatin1Char('z'))) {
- status = f.at(i);
- frm += f.at(i);
- } else if ((f.at(i) == QLatin1Char('d')) || (f.at(i) == QLatin1Char('M')) || (f.at(i) == QLatin1Char('y'))) {
- status = f.at(i);
- frm += f.at(i);
- } else if ((ap) && (f.at(i) == QLatin1Char('A'))) {
- status = QLatin1Char('P');
- frm += f.at(i);
- } else if((ap) && (f.at(i) == QLatin1Char('a'))) {
- status = QLatin1Char('p');
- frm += f.at(i);
+ if (cc == 'h' || cc == 'm' || cc == 'H' || cc == 's' || cc == 'z') {
+ status = cc;
+ frm += c;
+ } else if (cc == 'd' || cc == 'M' || cc == 'y') {
+ status = cc;
+ frm += c;
+ } else if (ap && cc == 'A') {
+ status = 'P';
+ frm += c;
+ } else if (ap && cc == 'a') {
+ status = 'p';
+ frm += c;
} else {
- buf += f.at(i);
- status = QLatin1Char('0');
+ buf += c;
+ status = '0';
}
}
}