diff options
author | Ariya Hidayat <ariya.hidayat@nokia.com> | 2009-08-31 10:28:11 (GMT) |
---|---|---|
committer | Ariya Hidayat <ariya.hidayat@nokia.com> | 2009-08-31 11:01:20 (GMT) |
commit | 98a6783f855318cc1be5857fd175a494c531fea2 (patch) | |
tree | b4af5b5badaf1b86c40e952c54ab7fd522d5bdf2 /src/svg/qsvghandler.cpp | |
parent | 076b5d3bc4a5b29886e946942ecd6eab1dde3d51 (diff) | |
download | Qt-98a6783f855318cc1be5857fd175a494c531fea2.zip Qt-98a6783f855318cc1be5857fd175a494c531fea2.tar.gz Qt-98a6783f855318cc1be5857fd175a494c531fea2.tar.bz2 |
Faster attributes iteration in QSvgAttributes constructor.
Use switch/case to give a faster short-cut when comparing strings.
Loading tiger.svg (tests/benchmarks/qsvgrenderer) is 3% faster now.
This is mostly because QSvgAttributes constructor goes down from 11.04
millions instructions to just 8.54 millions.
Reviewed-by: Kim
Diffstat (limited to 'src/svg/qsvghandler.cpp')
-rw-r--r-- | src/svg/qsvghandler.cpp | 256 |
1 files changed, 157 insertions, 99 deletions
diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index cdb6751..679bd5d 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -130,128 +130,186 @@ QSvgAttributes::QSvgAttributes(const QXmlStreamAttributes &xmlAttributes, QSvgHa if (!style.isEmpty()) { handler->parseCSStoXMLAttrs(style.toString(), &m_cssAttributes); for (int j = 0; j < m_cssAttributes.count(); ++j) { - const QSvgCssAttribute &attribute = m_cssAttributes.at(j ); + const QSvgCssAttribute &attribute = m_cssAttributes.at(j); QStringRef name = attribute.name; QStringRef value = attribute.value; + if (name.isEmpty()) + continue; + + switch (name.at(0).unicode()) { + + case 'c': + if (name == QLatin1String("color")) + color = value; + else if (name == QLatin1String("color-opacity")) + colorOpacity = value; + else if (name == QLatin1String("comp-op")) + compOp = value; + break; + + case 'd': + if (name == QLatin1String("display")) + display = value; + break; + + case 'f': + if (name == QLatin1String("fill")) + fill = value; + else if (name == QLatin1String("fill-rule")) + fillRule = value; + else if (name == QLatin1String("fill-opacity")) + fillOpacity = value; + else if (name == QLatin1String("font-family")) + fontFamily = value; + else if (name == QLatin1String("font-size")) + fontSize = value; + else if (name == QLatin1String("font-style")) + fontStyle = value; + else if (name == QLatin1String("font-weight")) + fontWeight = value; + else if (name == QLatin1String("font-variant")) + fontVariant = value; + break; + + case 'o': + if (name == QLatin1String("opacity")) + opacity = value; + else if (name == QLatin1String("offset")) + offset = value; + break; + + case 's': + if (name == QLatin1String("stroke")) + stroke = value; + else if (name == QLatin1String("stroke-dasharray")) + strokeDashArray = value; + else if (name == QLatin1String("stroke-dashoffset")) + strokeDashOffset = value; + else if (name == QLatin1String("stroke-linecap")) + strokeLineCap = value; + else if (name == QLatin1String("stroke-linejoin")) + strokeLineJoin = value; + else if (name == QLatin1String("stroke-miterlimit")) + strokeMiterLimit = value; + else if (name == QLatin1String("stroke-opacity")) + strokeOpacity = value; + else if (name == QLatin1String("stroke-width")) + strokeWidth = value; + else if (name == QLatin1String("stop-color")) + stopColor = value; + else if (name == QLatin1String("stop-opacity")) + stopOpacity = value; + break; + + case 't': + if (name == QLatin1String("text-anchor")) + textAnchor = value; + else if (name == QLatin1String("transform")) + transform = value; + break; + + case 'v': + if (name == QLatin1String("vector-effect")) + vectorEffect = value; + else if (name == QLatin1String("visibility")) + visibility = value; + break; + + default: + break; + } + } + } + + for (int i = 0; i < xmlAttributes.count(); ++i) { + const QXmlStreamAttribute &attribute = xmlAttributes.at(i); + QStringRef name = attribute.qualifiedName(); + if (name.isEmpty()) + continue; + QStringRef value = attribute.value(); + + switch (name.at(0).unicode()) { + + case 'c': if (name == QLatin1String("color")) color = value; - if (name == QLatin1String("color-opacity")) + else if (name == QLatin1String("color-opacity")) colorOpacity = value; + else if (name == QLatin1String("comp-op")) + compOp = value; + break; + + case 'd': + if (name == QLatin1String("display")) + display = value; + break; + + case 'f': if (name == QLatin1String("fill")) fill = value; - if (name == QLatin1String("fill-rule")) + else if (name == QLatin1String("fill-rule")) fillRule = value; - if (name == QLatin1String("fill-opacity")) + else if (name == QLatin1String("fill-opacity")) fillOpacity = value; + else if (name == QLatin1String("font-family")) + fontFamily = value; + else if (name == QLatin1String("font-size")) + fontSize = value; + else if (name == QLatin1String("font-style")) + fontStyle = value; + else if (name == QLatin1String("font-weight")) + fontWeight = value; + else if (name == QLatin1String("font-variant")) + fontVariant = value; + break; + + case 'o': + if (name == QLatin1String("opacity")) + opacity = value; + if (name == QLatin1String("offset")) + offset = value; + break; + + case 's': if (name == QLatin1String("stroke")) stroke = value; - if (name == QLatin1String("stroke-dasharray")) + else if (name == QLatin1String("stroke-dasharray")) strokeDashArray = value; - if (name == QLatin1String("stroke-dashoffset")) + else if (name == QLatin1String("stroke-dashoffset")) strokeDashOffset = value; - if (name == QLatin1String("stroke-linecap")) + else if (name == QLatin1String("stroke-linecap")) strokeLineCap = value; - if (name == QLatin1String("stroke-linejoin")) + else if (name == QLatin1String("stroke-linejoin")) strokeLineJoin = value; - if (name == QLatin1String("stroke-miterlimit")) + else if (name == QLatin1String("stroke-miterlimit")) strokeMiterLimit = value; - if (name == QLatin1String("stroke-opacity")) + else if (name == QLatin1String("stroke-opacity")) strokeOpacity = value; - if (name == QLatin1String("stroke-width")) + else if (name == QLatin1String("stroke-width")) strokeWidth = value; - if (name == QLatin1String("vector-effect")) - vectorEffect = value; - if (name == QLatin1String("font-family")) - fontFamily = value; - if (name == QLatin1String("font-size")) - fontSize = value; - if (name == QLatin1String("font-style")) - fontStyle = value; - if (name == QLatin1String("font-weight")) - fontWeight = value; - if (name == QLatin1String("font-variant")) - fontVariant = value; + else if (name == QLatin1String("stop-color")) + stopColor = value; + else if (name == QLatin1String("stop-opacity")) + stopOpacity = value; + break; + + case 't': if (name == QLatin1String("text-anchor")) textAnchor = value; - if (name == QLatin1String("transform")) + else if (name == QLatin1String("transform")) transform = value; - if (name == QLatin1String("visibility")) + break; + + case 'v': + if (name == QLatin1String("vector-effect")) + vectorEffect = value; + else if (name == QLatin1String("visibility")) visibility = value; - if (name == QLatin1String("opacity")) - opacity = value; - if (name == QLatin1String("comp-op")) - compOp = value; - if (name == QLatin1String("display")) - display = value; - if (name == QLatin1String("offset")) - offset = value; - if (name == QLatin1String("stop-color")) - stopColor = value; - if (name == QLatin1String("stop-opacity")) - stopOpacity = value; - } - } + break; - for (int i = 0; i < xmlAttributes.count(); ++i) { - const QXmlStreamAttribute &attribute = xmlAttributes.at(i); - QStringRef name = attribute.qualifiedName(); - QStringRef value = attribute.value(); - if (name == QLatin1String("color")) - color = value; - if (name == QLatin1String("color-opacity")) - colorOpacity = value; - if (name == QLatin1String("fill")) - fill = value; - if (name == QLatin1String("fill-rule")) - fillRule = value; - if (name == QLatin1String("fill-opacity")) - fillOpacity = value; - if (name == QLatin1String("stroke")) - stroke = value; - if (name == QLatin1String("stroke-dasharray")) - strokeDashArray = value; - if (name == QLatin1String("stroke-dashoffset")) - strokeDashOffset = value; - if (name == QLatin1String("stroke-linecap")) - strokeLineCap = value; - if (name == QLatin1String("stroke-linejoin")) - strokeLineJoin = value; - if (name == QLatin1String("stroke-miterlimit")) - strokeMiterLimit = value; - if (name == QLatin1String("stroke-opacity")) - strokeOpacity = value; - if (name == QLatin1String("stroke-width")) - strokeWidth = value; - if (name == QLatin1String("vector-effect")) - vectorEffect = value; - if (name == QLatin1String("font-family")) - fontFamily = value; - if (name == QLatin1String("font-size")) - fontSize = value; - if (name == QLatin1String("font-style")) - fontStyle = value; - if (name == QLatin1String("font-weight")) - fontWeight = value; - if (name == QLatin1String("font-variant")) - fontVariant = value; - if (name == QLatin1String("text-anchor")) - textAnchor = value; - if (name == QLatin1String("transform")) - transform = value; - if (name == QLatin1String("visibility")) - visibility = value; - if (name == QLatin1String("opacity")) - opacity = value; - if (name == QLatin1String("comp-op")) - compOp = value; - if (name == QLatin1String("display")) - display = value; - if (name == QLatin1String("offset")) - offset = value; - if (name == QLatin1String("stop-color")) - stopColor = value; - if (name == QLatin1String("stop-opacity")) - stopOpacity = value; + default: + break; + } } } |