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

List:       kde-commits
Subject:    KDE/kdelibs/khtml/css
From:       Viacheslav Tokarev <tsjoker () gmail ! com>
Date:       2009-03-09 17:35:20
Message-ID: 1236620120.153365.23736.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 937435 by vtokarev:

Another round of css selector optimizations:
- share same selectors cache between different collect() calls
- create properties once in a big chunk rather than allocate them separetely

 M  +30 -36    cssstyleselector.cpp  
 M  +7 -6      cssstyleselector.h  


--- trunk/KDE/kdelibs/khtml/css/cssstyleselector.cpp #937434:937435
@@ -608,8 +608,8 @@
     // do aggressive selection of selectors to check
     // instead of going over whole constructed list,
     // skip selectors that won't match for sure (e.g. with different id or class)
-    QVector<int> selectorsForCheck;
-    selectorsForCheck.reserve(selectors_size);
+    WTF::Vector<int> selectorsForCheck;
+    selectorsForCheck.reserveCapacity(selectors_size);
     // add unknown selectors to always be checked
     for (unsigned int i = 0; i < otherSelectors.size(); ++i)
         selectorsForCheck.append(otherSelectors[i]);
@@ -1829,12 +1829,9 @@
         delete [] selectorCache;
     }
     if ( properties ) {
-	CSSOrderedProperty **prop = properties;
-	while ( *prop ) {
-	    delete (*prop);
-	    prop++;
-	}
-        delete [] properties;
+        CSSOrderedProperty **prop = properties;
+        delete[] propertiesBuffer;
+        delete[] properties;
     }
     selectors = 0;
     properties = 0;
@@ -1879,26 +1876,27 @@
 
     QList<CSSSelector*> selectorList;
     CSSOrderedPropertyList propertyList;
+    WTF::HashMap<CSSSelector*, int> selectorsCache;
 
     if(defaultPrintStyle && m_medium->mediaTypeMatchSpecific("print"))
-      defaultPrintStyle->collect( &selectorList, &propertyList, Default,
+      defaultPrintStyle->collect(&selectorsCache, &selectorList, &propertyList, \
Default,  Default );
-    else if(defaultStyle) defaultStyle->collect( &selectorList, &propertyList,
+    else if(defaultStyle) defaultStyle->collect(&selectorsCache, &selectorList, \
&propertyList,  Default, Default );
 
     if (!strictParsing && defaultQuirksStyle)
-        defaultQuirksStyle->collect( &selectorList, &propertyList, Default, Default \
); +        defaultQuirksStyle->collect(&selectorsCache, &selectorList, \
&propertyList, Default, Default );  
-    if(userStyle) userStyle->collect(&selectorList, &propertyList, User, \
UserImportant ); +    if(userStyle) userStyle->collect(&selectorsCache, \
&selectorList, &propertyList, User, UserImportant );  
     if (defaultNonCSSHintsStyle)
-        defaultNonCSSHintsStyle->collect(&selectorList, &propertyList, NonCSSHint, \
NonCSSHint); +        defaultNonCSSHintsStyle->collect(&selectorsCache, \
&selectorList, &propertyList, NonCSSHint, NonCSSHint);  
     // Implicit styles are gathered from hidden, dynamically generated, implicit \
stylesheets.  // They have the same priority as presentational attributes.
-    if (implicitStyle) implicitStyle->collect(&selectorList, &propertyList, \
NonCSSHint, NonCSSHint); +    if (implicitStyle) \
implicitStyle->collect(&selectorsCache, &selectorList, &propertyList, NonCSSHint, \
NonCSSHint);  
-    if (authorStyle) authorStyle->collect(&selectorList, &propertyList, Author, \
AuthorImportant ); +    if (authorStyle) authorStyle->collect(&selectorsCache, \
&selectorList, &propertyList, Author, AuthorImportant );  
     selectors_size = selectorList.count();
     selectors = new CSSSelector *[selectors_size];
@@ -1951,9 +1949,12 @@
     qSort(propertyList.begin(), propertyList.end(), \
CSSOrderedPropertyList::compareItems);  properties_size = propertyList.count() + 1;
     properties = new CSSOrderedProperty *[ properties_size ];
+    propertiesBuffer = new CSSOrderedProperty[properties_size];
     CSSOrderedProperty **prop = properties;
-    for (QListIterator<CSSOrderedProperty*> pit(propertyList); pit.hasNext(); \
                ++prop)
-        *prop = pit.next();
+    for (int i = 0; i < propertyList.size(); ++i, ++prop) {
+        *prop = propertiesBuffer + i;
+        **prop = propertyList[i];
+    }
     *prop = 0;
 
     unsigned int* offsets = new unsigned int[selectors_size];
@@ -2098,41 +2099,36 @@
     }
 }
 
-void CSSStyleSelectorList::collect( QList<CSSSelector*> *selectorList, \
                CSSOrderedPropertyList *propList,
-				    Source regular, Source important )
+void CSSStyleSelectorList::collect(WTF::HashMap<CSSSelector*, int>* selectorsCache, \
QList<CSSSelector*> *selectorList, +        CSSOrderedPropertyList *propList, Source \
regular, Source important)  {
     CSSOrderedRule *r;
     QListIterator<CSSOrderedRule*> tIt(*this);
 
-    WTF::HashMap<CSSSelector*, int> cache;
-    QListIterator<CSSSelector*> it(*selectorList);
-    int pos = 0;
-    while (it.hasNext())
-        cache.set(it.next(), pos++);
-
+    propList->reserve(propList->size() + selectorList->size());
     while( tIt.hasNext() ) {
         r = tIt.next();
-        WTF::HashMap<CSSSelector*, int>::iterator cacheIterator = \
cache.find(r->selector); +        WTF::HashMap<CSSSelector*, int>::iterator \
cacheIterator = selectorsCache->find(r->selector);  int selectorNum;
-        if (cacheIterator == cache.end()) {
-            selectorNum = cache.size();
-            cache.set(r->selector, selectorNum);
+        if (cacheIterator == selectorsCache->end()) {
+            selectorNum = selectorsCache->size();
+            selectorsCache->set(r->selector, selectorNum);
             selectorList->append(r->selector);
         } else
             selectorNum = cacheIterator->second;
-        propList->append(r->rule->declaration(), selectorNum, \
r->selector->specificity(), regular, important ); +        \
propList->append(r->rule->declaration(), selectorNum, r->selector->specificity(), \
regular, important);  }
 }
 
 // -------------------------------------------------------------------------
 
-bool CSSOrderedPropertyList::compareItems(const CSSOrderedProperty * i1, const \
CSSOrderedProperty *i2) +bool CSSOrderedPropertyList::compareItems(const \
CSSOrderedProperty& i1, const CSSOrderedProperty& i2)  {
-    return *i1 < *i2;
+    return i1 < i2;
 }
 
 void CSSOrderedPropertyList::append(DOM::CSSStyleDeclarationImpl *decl, uint \
                selector, uint specificity,
-				    Source regular, Source important )
+                                    Source regular, Source important)
 {
     QList<CSSProperty*> *values = decl->values();
     if(!values) return;
@@ -2165,9 +2161,7 @@
             break;
         }
 
-	QList<CSSOrderedProperty*>::append(new CSSOrderedProperty(prop, selector,
-								 first, source, specificity,
-								 count() ));
+        QVector<CSSOrderedProperty>::append(CSSOrderedProperty(prop, selector, \
first, source, specificity, count()));  }
 }
 
--- trunk/KDE/kdelibs/khtml/css/cssstyleselector.h #937434:937435
@@ -294,6 +294,7 @@
 	SelectorCache *selectorCache;
 	unsigned int properties_size;
 	CSSOrderedProperty **properties;
+        CSSOrderedProperty *propertiesBuffer;
 	QVarLengthArray<CSSOrderedProperty> inlineProps;
         MediaQueryEvaluator* m_medium;
 	CSSOrderedProperty **propsToApply;
@@ -331,12 +332,12 @@
      * This is the list we will collect all properties we need to apply in.
      * It will get sorted once before applying.
      */
-    class CSSOrderedPropertyList : public QList<CSSOrderedProperty*>
+    class CSSOrderedPropertyList : public QVector<CSSOrderedProperty>
     {
     public:
-	static bool compareItems(const CSSOrderedProperty* i1, const CSSOrderedProperty* \
                i2);
-	void append(DOM::CSSStyleDeclarationImpl *decl, uint selector, uint specificity,
-		    Source regular, Source important );
+        static bool compareItems(const CSSOrderedProperty& i1, const \
CSSOrderedProperty& i2); +        void append(DOM::CSSStyleDeclarationImpl *decl, \
uint selector, uint specificity, +                    Source regular, Source \
important);  };
 
     class CSSOrderedRule
@@ -359,8 +360,8 @@
 	void append( DOM::CSSStyleSheetImpl *sheet,
 		     MediaQueryEvaluator *medium, CSSStyleSelector* styleSelector );
 
-	void collect( QList<DOM::CSSSelector*> *selectorList, CSSOrderedPropertyList \
                *propList,
-		      Source regular, Source important );
+        void collect(WTF::HashMap<DOM::CSSSelector*, int>* selectorsCache, \
QList<DOM::CSSSelector*> *selectorList, +                CSSOrderedPropertyList \
*propList, Source regular, Source important);  };
 
 }


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

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