diff options
author | Ariya Hidayat <ariya.hidayat@nokia.com> | 2009-09-01 11:22:04 (GMT) |
---|---|---|
committer | Ariya Hidayat <ariya.hidayat@nokia.com> | 2009-09-01 15:46:21 (GMT) |
commit | 8fab695b7987856da4ebb6b36410dd05aa48c13d (patch) | |
tree | cd160cb23c6de78d0a803e4c146d419a629936a8 /src/svg | |
parent | e86ddf19ca20cb2128465b42fae4a9129abe25b3 (diff) | |
download | Qt-8fab695b7987856da4ebb6b36410dd05aa48c13d.zip Qt-8fab695b7987856da4ebb6b36410dd05aa48c13d.tar.gz Qt-8fab695b7987856da4ebb6b36410dd05aa48c13d.tar.bz2 |
Use QStringRef when parsing SVG transformation matrix.
There is really no need to use QString for parsing the matrix, hence
use QStringRef. In a complex SVG, this cuts significantly the time
spent in parseTransform().
Reviewed-by: Kim
Diffstat (limited to 'src/svg')
-rw-r--r-- | src/svg/qsvghandler.cpp | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index 371b845..27de011 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -685,6 +685,28 @@ static QString idFromUrl(const QString &url) return id; } +static inline QStringRef trimRef(const QStringRef &str) +{ + if (str.isEmpty()) + return QStringRef(); + const QChar *s = str.string()->constData() + str.position(); + int end = str.length() - 1; + if (!s[0].isSpace() && !s[end].isSpace()) + return str; + + int start = 0; + while (start<=end && s[start].isSpace()) // skip white space from start + start++; + if (start <= end) { // only white space + while (s[end].isSpace()) // skip white space from end + end--; + } + int l = end - start + 1; + if (l <= 0) + return QStringRef(); + return QStringRef(str.string(), str.position() + start, l); +} + /** * returns true when successfuly set the color. false signifies * that the color should be inherited @@ -903,12 +925,16 @@ static void parseBrush(QSvgNode *node, -static QMatrix parseTransformationMatrix(const QString &value) +static QMatrix parseTransformationMatrix(const QStringRef &value) { + if (value.isEmpty()) + return QMatrix(); + QMatrix matrix; const QChar *str = value.constData(); + const QChar *end = str + value.length(); - while (*str != QLatin1Char(0)) { + while (str < end) { if (str->isSpace() || *str == QLatin1Char(',')) { ++str; continue; @@ -973,7 +999,7 @@ static QMatrix parseTransformationMatrix(const QString &value) } - while (str->isSpace()) + while (str < end && str->isSpace()) ++str; if (*str != QLatin1Char('(')) goto error; @@ -1212,10 +1238,7 @@ static void parseTransform(QSvgNode *node, { if (attributes.transform.isEmpty()) return; - QString value = attributes.transform.toString().trimmed(); - if (value.isEmpty()) - return; - QMatrix matrix = parseTransformationMatrix(value); + QMatrix matrix = parseTransformationMatrix(trimRef(attributes.transform)); if (!matrix.isIdentity()) { node->appendStyleProperty(new QSvgTransformStyle(QTransform(matrix)), someId(attributes)); @@ -2583,7 +2606,7 @@ static void parseBaseGradient(QSvgNode *node, QSvgHandler *handler) { QString link = attributes.value(QLatin1String("xlink:href")).toString(); - QString trans = attributes.value(QLatin1String("gradientTransform")).toString(); + QStringRef trans = attributes.value(QLatin1String("gradientTransform")); QString spread = attributes.value(QLatin1String("spreadMethod")).toString(); QString units = attributes.value(QLatin1String("gradientUnits")).toString(); |