Title: [144544] trunk/Source/WebCore
Revision
144544
Author
[email protected]
Date
2013-03-02 13:06:57 -0800 (Sat, 02 Mar 2013)

Log Message

Remove two unnecessary mallocs from the main-thread-parser code path
https://bugs.webkit.org/show_bug.cgi?id=111249

Reviewed by Adam Barth.

I noticed these while fixing up our Vector -> String conversions
but never went back to fix the FIXME.

AtomicString(Vector<UChar, capacity>) is smart enough to avoid mallocing
if the represented string is already in the AtomicString table.  It
also handles 8bit vs. 16bit and empty() just like nameString() does.

I also removed a 3rd caller to nameString() in the XSSAuditor which
was causing an unnecessary malloc in both the main and background
thread parser paths.

* html/parser/AtomicHTMLToken.h:
(WebCore::AtomicHTMLToken::AtomicHTMLToken):
* html/parser/HTMLToken.h:
* html/parser/XSSAuditor.cpp:
(WebCore):
(WebCore::threadSafeMatch):
(WebCore::hasName):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (144543 => 144544)


--- trunk/Source/WebCore/ChangeLog	2013-03-02 18:09:53 UTC (rev 144543)
+++ trunk/Source/WebCore/ChangeLog	2013-03-02 21:06:57 UTC (rev 144544)
@@ -1,5 +1,31 @@
 2013-03-02  Eric Seidel  <[email protected]>
 
+        Remove two unnecessary mallocs from the main-thread-parser code path
+        https://bugs.webkit.org/show_bug.cgi?id=111249
+
+        Reviewed by Adam Barth.
+
+        I noticed these while fixing up our Vector -> String conversions
+        but never went back to fix the FIXME.
+
+        AtomicString(Vector<UChar, capacity>) is smart enough to avoid mallocing
+        if the represented string is already in the AtomicString table.  It
+        also handles 8bit vs. 16bit and empty() just like nameString() does.
+
+        I also removed a 3rd caller to nameString() in the XSSAuditor which
+        was causing an unnecessary malloc in both the main and background
+        thread parser paths.
+
+        * html/parser/AtomicHTMLToken.h:
+        (WebCore::AtomicHTMLToken::AtomicHTMLToken):
+        * html/parser/HTMLToken.h:
+        * html/parser/XSSAuditor.cpp:
+        (WebCore):
+        (WebCore::threadSafeMatch):
+        (WebCore::hasName):
+
+2013-03-02  Eric Seidel  <[email protected]>
+
         constructTreeFromCompactHTMLToken should call clearExternalCharacters
         https://bugs.webkit.org/show_bug.cgi?id=111248
 

Modified: trunk/Source/WebCore/html/parser/AtomicHTMLToken.h (144543 => 144544)


--- trunk/Source/WebCore/html/parser/AtomicHTMLToken.h	2013-03-02 18:09:53 UTC (rev 144543)
+++ trunk/Source/WebCore/html/parser/AtomicHTMLToken.h	2013-03-02 21:06:57 UTC (rev 144544)
@@ -153,7 +153,7 @@
             ASSERT_NOT_REACHED();
             break;
         case HTMLToken::DOCTYPE:
-            m_name = AtomicString(token.nameString()); // FIXME: Should be AtomicString(token.name()) to avoid mallocing every time.
+            m_name = AtomicString(token.name());
             m_doctypeData = token.releaseDoctypeData();
             break;
         case HTMLToken::EndOfFile:
@@ -161,7 +161,7 @@
         case HTMLToken::StartTag:
         case HTMLToken::EndTag: {
             m_selfClosing = token.selfClosing();
-            m_name = AtomicString(token.nameString()); // FIXME: Should be AtomicString(token.name()) to avoid mallocing every time.
+            m_name = AtomicString(token.name());
             initializeAttributes(token.attributes());
             break;
         }

Modified: trunk/Source/WebCore/html/parser/HTMLToken.h (144543 => 144544)


--- trunk/Source/WebCore/html/parser/HTMLToken.h	2013-03-02 18:09:53 UTC (rev 144543)
+++ trunk/Source/WebCore/html/parser/HTMLToken.h	2013-03-02 21:06:57 UTC (rev 144544)
@@ -151,16 +151,6 @@
         m_orAllData |= character;
     }
 
-    // FIXME: Rename this to copyNameAsString().
-    String nameString() const
-    {
-        if (!m_data.size())
-            return emptyString();
-        if (isAll8BitData())
-            return String::make8BitFrom16BitSource(m_data.data(), m_data.size());
-        return String(m_data);
-    }
-
     /* DOCTYPE Tokens */
 
     bool forceQuirks() const

Modified: trunk/Source/WebCore/html/parser/XSSAuditor.cpp (144543 => 144544)


--- trunk/Source/WebCore/html/parser/XSSAuditor.cpp	2013-03-02 18:09:53 UTC (rev 144543)
+++ trunk/Source/WebCore/html/parser/XSSAuditor.cpp	2013-03-02 21:06:57 UTC (rev 144544)
@@ -113,9 +113,16 @@
     return (start + 1 < string.length() && string[start] == '/' && string[start+1] == '*');
 }
 
+// If other files need this, we should move this to HTMLParserIdioms.h
+template<size_t inlineCapacity>
+bool threadSafeMatch(const Vector<UChar, inlineCapacity>& vector, const QualifiedName& qname)
+{
+    return equalIgnoringNullity(vector, qname.localName().impl());
+}
+
 static bool hasName(const HTMLToken& token, const QualifiedName& name)
 {
-    return threadSafeMatch(token.nameString(), name);
+    return threadSafeMatch(token.name(), name);
 }
 
 static bool findAttributeWithName(const HTMLToken& token, const QualifiedName& name, size_t& indexOfMatchingAttribute)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to