src/hbcore/cssparser/hblayeredstyleloader_p.cpp
changeset 30 80e4d18b72f5
parent 28 b7da29130b0e
--- a/src/hbcore/cssparser/hblayeredstyleloader_p.cpp	Fri Sep 17 08:32:10 2010 +0300
+++ b/src/hbcore/cssparser/hblayeredstyleloader_p.cpp	Mon Oct 04 00:38:12 2010 +0300
@@ -116,10 +116,12 @@
 void HbLayeredStyleLoader::init(Concern con)
 {
     mConcern = con;
-    if (con != Concern_All) {
-        HbLayeredStyleLoader *allStack = getStack(Concern_All);
-        if (allStack) {
-            mUsedLayers = allStack->mUsedLayers;
+    if (con == Concern_All) {
+        mAllStack = 0;
+    } else {
+        mAllStack = getStack(Concern_All);
+        if (mAllStack) {
+            mUsedLayers = mAllStack->mUsedLayers;
         }
     }
 #ifdef HB_USETHEMESERVER
@@ -308,11 +310,15 @@
 {
     QVector<int> fileList;
 
+    bool dirPathHasSeparator = dirPath.endsWith(QDir::separator());
+
     QDir dir(dirPath, CSS_FILTER, sort, QDir::Readable | QDir::Files);
     QStringList files = dir.entryList();
+    fileList.reserve(files.count());
+
     for (QStringList::Iterator it = files.begin(); it != files.end(); ++it) {
         QString cssPath = dirPath;
-        if (!dirPath.endsWith(QDir::separator())) {
+        if (!dirPathHasSeparator) {
             cssPath.append(QDir::separator());
         }
         cssPath.append(*it);
@@ -408,14 +414,14 @@
 }
 
 
-static inline bool qcss_selectorStyleRuleLessThan(
-    const QPair<int, HbCss::StyleRule> &lhs, const QPair<int, HbCss::StyleRule> &rhs)
+static inline bool qcss_selectorStyleRuleLessThan(const HbCss::WeightedRule &lhs, 
+                                                  const HbCss::WeightedRule &rhs)
 {
     return lhs.first < rhs.first;
 }
 
-static inline bool qcss_selectorDeclarationLessThan(
-    const QPair<int, HbCss::Declaration> &lhs, const QPair<int, HbCss::Declaration> &rhs)
+static inline bool qcss_selectorDeclarationLessThan(const HbCss::WeightedDeclaration &lhs, 
+                                                    const HbCss::WeightedDeclaration &rhs)
 {
     return lhs.first < rhs.first;
 }
@@ -426,9 +432,6 @@
     HbWidget* widget = (HbWidget*) node.ptr;
     HbWidgetStyleLoader *loader = HbWidgetStyleLoader::instance();
     loader->loadCss(widget);
-    
-    QVector<QVector<HbCss::WeightedRule> > weightedRulesList;
-    HbLayeredStyleLoader *allStack = mConcern == Concern_All ? 0 : getStack(Concern_All);
 
     QListIterator<LayerPriority> iter(mUsedLayers);
     while (iter.hasNext()) {
@@ -439,10 +442,10 @@
                 return true;
             }
         }
-        if (allStack) {
+        if (mAllStack) {
             QMap<LayerPriority, Layer>::const_iterator allIt = 
-                allStack->mStyleLayers.constFind(priority);
-            if (allIt != allStack->mStyleLayers.constEnd()) {
+                mAllStack->mStyleLayers.constFind(priority);
+            if (allIt != mAllStack->mStyleLayers.constEnd()) {
                 if (allIt->styleSelector.hasOrientationSpecificStyleRules(node)) {
                     return true;
                 }
@@ -467,43 +470,39 @@
     HbWidget* widget = (HbWidget*) node.ptr;
     HbWidgetStyleLoader *loader = HbWidgetStyleLoader::instance();
     loader->loadCss(widget);
-    
-    QVector<QVector<HbCss::WeightedDeclaration> > weightedDeclsList;
-    HbLayeredStyleLoader *allStack = mConcern == Concern_All ? 0 : getStack(Concern_All);
+
+    QList<HbCss::WeightedDeclaration> weightedDecls;
 
     QListIterator<LayerPriority> iter(mUsedLayers);
     while (iter.hasNext()) {
         LayerPriority priority = iter.next();
         QMap<LayerPriority, Layer>::const_iterator it = mStyleLayers.constFind(priority);
         if (it != mStyleLayers.constEnd()) {
-            weightedDeclsList.append(
-                it->styleSelector.weightedDeclarationsForNode(node, orientation, extraPseudo));
+            it->styleSelector.weightedDeclarationsForNode(
+                node, 
+                orientation, 
+                &weightedDecls, 
+                extraPseudo);
         }
-        if (allStack) {
+        if (mAllStack) {
             QMap<LayerPriority, Layer>::const_iterator allIt = 
-                allStack->mStyleLayers.constFind(priority);
-            if (allIt != allStack->mStyleLayers.constEnd()) {
-                weightedDeclsList.append(
-                    allIt->styleSelector.weightedDeclarationsForNode(
-                        node, 
-                        orientation, 
-                        extraPseudo));
+                mAllStack->mStyleLayers.constFind(priority);
+            if (allIt != mAllStack->mStyleLayers.constEnd()) {
+                allIt->styleSelector.weightedDeclarationsForNode(
+                    node, 
+                    orientation, 
+                    &weightedDecls,
+                    extraPseudo);
             }
         }
     }
     
-    QVector<HbCss::WeightedDeclaration> weightedDecls;
-    int count = 0;
-    for (int i=0; i<weightedDeclsList.count(); i++) {
-        count += weightedDeclsList.at(i).count();
+    if (weightedDecls.count() > 1) {
+        qStableSort(weightedDecls.begin(), weightedDecls.end(), qcss_selectorDeclarationLessThan);
     }
-    weightedDecls.reserve(count);
-    for (int i=0; i<weightedDeclsList.count(); i++) {
-        weightedDecls += weightedDeclsList.at(i);
-    }
-    qStableSort(weightedDecls.begin(), weightedDecls.end(), qcss_selectorDeclarationLessThan);
 
     HbVector<HbCss::Declaration> decls;
+    decls.reserve(weightedDecls.count());
     for (int j = 0; j < weightedDecls.count(); j++)
         decls += weightedDecls.at(j).second;
     return decls;
@@ -519,50 +518,38 @@
         const Qt::Orientation orientation) const
 {
     HbWidget* widget = (HbWidget*) node.ptr;
-    HbWidgetStyleLoader *loader = HbWidgetStyleLoader::instance();
-    loader->loadCss(widget);
-    
-    QVector<QVector<HbCss::WeightedRule> > weightedRulesList;
-    HbLayeredStyleLoader *allStack = mConcern == Concern_All ? 0 : getStack(Concern_All);
+    HbWidgetStyleLoader::instance()->loadCss(widget);
+
+    QList<HbCss::WeightedRule> weightedRules;
 
     QListIterator<LayerPriority> iter(mUsedLayers);
     while (iter.hasNext()) {
         LayerPriority priority = iter.next();
         QMap<LayerPriority, Layer>::const_iterator it = mStyleLayers.constFind(priority);
         if (it != mStyleLayers.constEnd()) {
-            weightedRulesList.append(
-                it->styleSelector.weightedStyleRulesForNode(node, orientation));
+            it->styleSelector.weightedStyleRulesForNode(node, orientation, &weightedRules);
         }
-        if (allStack) {
+        if (mAllStack) {
             QMap<LayerPriority, Layer>::const_iterator allIt = 
-                allStack->mStyleLayers.constFind(priority);
-            if (allIt != allStack->mStyleLayers.constEnd()) {
-                weightedRulesList.append(
-                    allIt->styleSelector.weightedStyleRulesForNode(node, orientation));
+                mAllStack->mStyleLayers.constFind(priority);
+            if (allIt != mAllStack->mStyleLayers.constEnd()) {
+                allIt->styleSelector.weightedStyleRulesForNode(node, orientation, &weightedRules);
             }
         }
     }
-    
-    QVector<HbCss::WeightedRule> weightedRules;
-    int count = 0;
-    for (int i=0; i<weightedRulesList.count(); i++) {
-        count += weightedRulesList.at(i).count();
+    if (weightedRules.count() > 1) {
+        qStableSort(weightedRules.begin(), weightedRules.end(), qcss_selectorStyleRuleLessThan);
     }
-    weightedRules.reserve(count);
-    for (int i=0; i<weightedRulesList.count(); i++) {
-        weightedRules += weightedRulesList.at(i);
-    }
-    qStableSort(weightedRules.begin(), weightedRules.end(), qcss_selectorStyleRuleLessThan);
 
-    HbVector<HbCss::StyleRule> rules;
 #ifdef LAYEREDSTYLELOADER_DEBUG
     qDebug() << "Style rules for" << widget->metaObject()->className();
     qDebug("\n%s", HbCssFormatter::weightedStyleRulesToString(weightedRules).toLatin1().constData());
 #endif
-    rules.reserve(count);
-    for (int j = 0; j < weightedRules.count(); j++) {
+
+    HbVector<HbCss::StyleRule> rules;
+    rules.reserve(weightedRules.count());
+    for (int j = 0; j < weightedRules.count(); j++)
         rules += weightedRules.at(j).second;
-    }
     return rules;
 }
 
@@ -572,8 +559,6 @@
 */
 void HbLayeredStyleLoader::variableRuleSets(QHash<quint32, HbCss::Declaration> *variables) const
 {
-    HbLayeredStyleLoader *allStack = mConcern == Concern_All ? 0 : getStack(Concern_All);
-    
     QListIterator<LayerPriority> iter(mUsedLayers);
     while (iter.hasNext()) {
         LayerPriority priority = iter.next();
@@ -593,10 +578,10 @@
                 }
             }
         }
-        if (allStack) {
+        if (mAllStack) {
             QMap<LayerPriority, Layer>::const_iterator allIt = 
-                allStack->mStyleLayers.constFind(priority);
-            if (allIt != allStack->mStyleLayers.constEnd()) {
+                mAllStack->mStyleLayers.constFind(priority);
+            if (allIt != mAllStack->mStyleLayers.constEnd()) {
                 allIt->styleSelector.variableRuleSets(variables);
             }
         }