[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/libs/kotext
From:       Thorsten Zachmann <t.zachmann () zagge ! de>
Date:       2010-10-22 10:44:27
Message-ID: 20101022104427.31803AC897 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1188417 by zachmann:

Optimize usage of hasAttributeNS

Optimize the code to use attributeNS directly without the use of hasAttributeNS.
That removes the need for a second lookup which is much more expensive then
checking if the return value was empty.


 M  +3 -2      opendocument/KoTextLoader.cpp  
 M  +18 -12    styles/KoListLevelProperties.cpp  


--- trunk/koffice/libs/kotext/opendocument/KoTextLoader.cpp #1188416:1188417
@@ -446,14 +446,15 @@
 
     // Some paragraph have id's defined which we need to store so that we can eg
     // attach text animations to this specific paragraph later on
-    if (element.hasAttributeNS(KoXmlNS::text, "id") && d->shape) {
+    QString id(element.attributeNS(KoXmlNS::text, "id"));
+    if (!id.isEmpty() && d->shape) {
         QTextBlock block = cursor.block();
         KoTextBlockData *data = dynamic_cast<KoTextBlockData*>(block.userData());
         if (!data) {
             data = new KoTextBlockData();
             block.setUserData(data);
         }
-        d->context.addShapeSubItemId(d->shape, QVariant::fromValue(data), \
element.attributeNS(KoXmlNS::text, "id")); +        \
d->context.addShapeSubItemId(d->shape, QVariant::fromValue(data), id);  }
 
     // attach Rdf to cursor.block()
--- trunk/koffice/libs/kotext/styles/KoListLevelProperties.cpp #1188416:1188417
@@ -495,23 +495,29 @@
             continue;
         const QString localName = property.localName();
         if (localName == "list-level-properties") {
-            if (property.hasAttributeNS(KoXmlNS::text, "space-before"))
-                setIndent(KoUnit::parseValue(property.attributeNS(KoXmlNS::text, \
"space-before"))); +            QString \
spaceBefore(property.attributeNS(KoXmlNS::text, "space-before")); +            if \
(!spaceBefore.isEmpty()) +                setIndent(KoUnit::parseValue(spaceBefore));
 
-            if (property.hasAttributeNS(KoXmlNS::text, "min-label-width"))
-                setMinimumWidth(KoUnit::parseValue(property.attributeNS(KoXmlNS::text, \
"min-label-width"))); +            QString \
minLableWidth(property.attributeNS(KoXmlNS::text, "min-label-width")); +            \
if (!minLableWidth.isEmpty()) +                \
setMinimumWidth(KoUnit::parseValue(minLableWidth));  
-            if (property.hasAttributeNS(KoXmlNS::fo, "text-align"))
-                setAlignment(KoText::alignmentFromString(property.attributeNS(KoXmlNS::fo, \
"text-align"))); +            QString textAlign(property.attributeNS(KoXmlNS::fo, \
"text-align")); +            if (!textAlign.isEmpty())
+                setAlignment(KoText::alignmentFromString(textAlign));
 
-            if (property.hasAttributeNS(KoXmlNS::text, "min-label-distance"))
-                setMinimumDistance(KoUnit::parseValue(property.attributeNS(KoXmlNS::text, \
"min-label-distance"))); +            QString \
minLableDistance(property.attributeNS(KoXmlNS::text, "min-label-distance")); +        \
if (!minLableDistance.isEmpty()) +                \
setMinimumDistance(KoUnit::parseValue(minLableDistance));  
-            if (property.hasAttributeNS(KoXmlNS::fo, "width"))
-                setWidth(KoUnit::parseValue(property.attributeNS(KoXmlNS::fo, \
"width"))); +            QString width(property.attributeNS(KoXmlNS::fo, "width"));
+            if (!width.isEmpty())
+                setWidth(KoUnit::parseValue(width));
 
-            if (property.hasAttributeNS(KoXmlNS::fo, "height"))
-                setHeight(KoUnit::parseValue(property.attributeNS(KoXmlNS::fo, \
"height"))); +            QString height(property.attributeNS(KoXmlNS::fo, \
"height")); +            if (!height.isEmpty())
+                setHeight(KoUnit::parseValue(height));
         } else if (localName == "text-properties") {
             // TODO
         }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic