summaryrefslogtreecommitdiffstats
path: root/src/svg
diff options
context:
space:
mode:
authorAriya Hidayat <ariya.hidayat@nokia.com>2009-09-02 09:50:45 (GMT)
committerAriya Hidayat <ariya.hidayat@nokia.com>2009-09-02 11:04:57 (GMT)
commit4fd28ba87492f2f4725e48f1a3e30ed8cd099081 (patch)
tree8076abf19b71cc2ca9e8799c3a6be745895997f6 /src/svg
parentf8bd803e6eac2d5c25fec9cb50b54128c57b6725 (diff)
downloadQt-4fd28ba87492f2f4725e48f1a3e30ed8cd099081.zip
Qt-4fd28ba87492f2f4725e48f1a3e30ed8cd099081.tar.gz
Qt-4fd28ba87492f2f4725e48f1a3e30ed8cd099081.tar.bz2
Faster SVG color parsing by tackling the #rrggbb color early.
If the color starts with '#', let's parse it ourselves rather than waiting for the (fall-back) QColor-from-QString which even requires us to create a QString out of the QStringRef. All widely used illustration programs output SVG with #rrggbb format to specify the color. Loading tiger.svg (tests/benchmarks/qsvgrenderer) enjoys 2.4% speed-up. Reviewed-by: Kim
Diffstat (limited to 'src/svg')
-rw-r--r--src/svg/qsvghandler.cpp78
1 files changed, 47 insertions, 31 deletions
diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp
index 6620707..38ffe3e 100644
--- a/src/svg/qsvghandler.cpp
+++ b/src/svg/qsvghandler.cpp
@@ -65,6 +65,7 @@
#include "qmath.h"
#include "qnumeric.h"
#include "qvarlengtharray.h"
+#include "private/qcolor_p.h"
#include "private/qmath_p.h"
#include "float.h"
@@ -718,40 +719,55 @@ static bool resolveColor(const QStringRef &colorStr, QColor &color, QSvgHandler
return false;
switch(colorStrTr.at(0).unicode()) {
- case 'r': {
- // starts with "rgb("
- if (colorStrTr == QLatin1String("rgb(")) {
- const QChar *s = colorStrTr.constData() + 4;
- QVector<qreal> compo = parseNumbersList(s);
- //1 means that it failed after reaching non-parsable
- //character which is going to be "%"
- if (compo.size() == 1) {
- const QChar *s = colorStrTr.constData() + 4;
- compo = parsePercentageList(s);
- compo[0] *= (qreal)2.55;
- compo[1] *= (qreal)2.55;
- compo[2] *= (qreal)2.55;
+
+ case '#':
+ {
+ // #rrggbb is very very common, so let's tackle it here
+ // rather than falling back to QColor
+ QRgb rgb;
+ bool ok = qt_get_hex_rgb(colorStrTr.unicode(), colorStrTr.length(), &rgb);
+ if (ok)
+ color.setRgb(rgb);
+ return ok;
}
+ break;
+
+ case 'r':
+ {
+ // starts with "rgb("
+ if (colorStrTr == QLatin1String("rgb(")) {
+ const QChar *s = colorStrTr.constData() + 4;
+ QVector<qreal> compo = parseNumbersList(s);
+ //1 means that it failed after reaching non-parsable
+ //character which is going to be "%"
+ if (compo.size() == 1) {
+ const QChar *s = colorStrTr.constData() + 4;
+ compo = parsePercentageList(s);
+ compo[0] *= (qreal)2.55;
+ compo[1] *= (qreal)2.55;
+ compo[2] *= (qreal)2.55;
+ }
- color = QColor(int(compo[0]),
- int(compo[1]),
- int(compo[2]));
- return true;
+ color = QColor(int(compo[0]),
+ int(compo[1]),
+ int(compo[2]));
+ return true;
+ }
}
- }
- break;
- case 'c':
- if (colorStrTr == QLatin1String("currentColor")) {
- color = handler->currentColor();
- return true;
- }
- break;
- case 'i':
- if (colorStrTr == QT_INHERIT)
- return false;
- break;
- default:
- break;
+ break;
+
+ case 'c':
+ if (colorStrTr == QLatin1String("currentColor")) {
+ color = handler->currentColor();
+ return true;
+ }
+ break;
+ case 'i':
+ if (colorStrTr == QT_INHERIT)
+ return false;
+ break;
+ default:
+ break;
}
color = QColor(colorStrTr.toString());