From f8bd803e6eac2d5c25fec9cb50b54128c57b6725 Mon Sep 17 00:00:00 2001 From: Ariya Hidayat Date: Wed, 2 Sep 2009 11:05:02 +0200 Subject: Minor speed-up when parsing SVG color. Loading tiger.svg (tests/benchmarks/qsvgrenderer) enjoys 1% speed-up. Reviewed-by: Kim --- src/svg/qsvghandler.cpp | 54 +++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index 9459af6..6620707 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -716,28 +716,42 @@ static bool resolveColor(const QStringRef &colorStr, QColor &color, QSvgHandler QStringRef colorStrTr = trimRef(colorStr); if (colorStrTr.isEmpty()) return false; - if (colorStrTr == QLatin1String("rgb(")) { - const QChar *s = colorStrTr.constData() + 4; - QVector compo = parseNumbersList(s); - //1 means that it failed after reaching non-parsable - //character which is going to be "%" - if (compo.size() == 1) { + + switch(colorStrTr.at(0).unicode()) { + case 'r': { + // starts with "rgb(" + if (colorStrTr == QLatin1String("rgb(")) { const QChar *s = colorStrTr.constData() + 4; - compo = parsePercentageList(s); - compo[0] *= (qreal)2.55; - compo[1] *= (qreal)2.55; - compo[2] *= (qreal)2.55; - } + QVector 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; - } else if (colorStrTr == QT_INHERIT) { - return false; - } else if (colorStrTr == QLatin1String("currentColor")) { - color = handler->currentColor(); - 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; } color = QColor(colorStrTr.toString()); -- cgit v0.12