Title: [166046] trunk/Source
Revision
166046
Author
[email protected]
Date
2014-03-21 00:12:07 -0700 (Fri, 21 Mar 2014)

Log Message

Add a combined decodeAndFlush to TextResourceDecoder
https://bugs.webkit.org/show_bug.cgi?id=130560

Reviewed by Andreas Kling.

Source/WebCore:

* WebCore.exp.in: Added new symbol for decodeAndFlush. Also re-did
the geometry types #if so it would sort more logically.

* fileapi/FileReaderLoader.cpp:
(WebCore::FileReaderLoader::convertToText): Use decodeAndFlush.
* inspector/InspectorPageAgent.cpp:
(WebCore::InspectorPageAgent::cachedResourceContent): Ditto.
* inspector/NetworkResourcesData.cpp:
(WebCore::NetworkResourcesData::ResourceData::decodeDataToContent): Ditto.

* loader/TextResourceDecoder.cpp:
(WebCore::TextResourceDecoder::decodeAndFlush): Added.
* loader/TextResourceDecoder.h: Ditto.

* loader/appcache/ManifestParser.cpp:
(WebCore::parseManifest): Use decodeAndFlush.
* loader/cache/CachedCSSStyleSheet.cpp:
(WebCore::CachedCSSStyleSheet::sheetText): Ditto.
(WebCore::CachedCSSStyleSheet::finishLoading): Ditto.

* loader/cache/CachedFont.cpp:
(WebCore::CachedFont::ensureSVGFontData): Use decodeAndFlush. Also use nullptr.
(WebCore::CachedFont::getSVGFontById): Use descendantsOfType<SVGFontElement>
instead of using a NodeList. Much more efficient!

* loader/cache/CachedSVGDocument.cpp:
(WebCore::CachedSVGDocument::finishLoading): Use decodeAndFlush.
* loader/cache/CachedScript.cpp:
(WebCore::CachedScript::script): Ditto.
* loader/cache/CachedXSLStyleSheet.cpp:
(WebCore::CachedXSLStyleSheet::finishLoading): Ditto.
* page/Page.cpp:
(WebCore::Page::userStyleSheet): Ditto.

Source/WebKit/mac:

* WebView/WebView.mm:
(+[WebView _decodeData:]): Use decodeAndFlush.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (166045 => 166046)


--- trunk/Source/WebCore/ChangeLog	2014-03-21 06:51:18 UTC (rev 166045)
+++ trunk/Source/WebCore/ChangeLog	2014-03-21 07:12:07 UTC (rev 166046)
@@ -1,3 +1,44 @@
+2014-03-21  Darin Adler  <[email protected]>
+
+        Add a combined decodeAndFlush to TextResourceDecoder
+        https://bugs.webkit.org/show_bug.cgi?id=130560
+
+        Reviewed by Andreas Kling.
+
+        * WebCore.exp.in: Added new symbol for decodeAndFlush. Also re-did
+        the geometry types #if so it would sort more logically.
+
+        * fileapi/FileReaderLoader.cpp:
+        (WebCore::FileReaderLoader::convertToText): Use decodeAndFlush.
+        * inspector/InspectorPageAgent.cpp:
+        (WebCore::InspectorPageAgent::cachedResourceContent): Ditto.
+        * inspector/NetworkResourcesData.cpp:
+        (WebCore::NetworkResourcesData::ResourceData::decodeDataToContent): Ditto.
+
+        * loader/TextResourceDecoder.cpp:
+        (WebCore::TextResourceDecoder::decodeAndFlush): Added.
+        * loader/TextResourceDecoder.h: Ditto.
+
+        * loader/appcache/ManifestParser.cpp:
+        (WebCore::parseManifest): Use decodeAndFlush.
+        * loader/cache/CachedCSSStyleSheet.cpp:
+        (WebCore::CachedCSSStyleSheet::sheetText): Ditto.
+        (WebCore::CachedCSSStyleSheet::finishLoading): Ditto.
+
+        * loader/cache/CachedFont.cpp:
+        (WebCore::CachedFont::ensureSVGFontData): Use decodeAndFlush. Also use nullptr.
+        (WebCore::CachedFont::getSVGFontById): Use descendantsOfType<SVGFontElement>
+        instead of using a NodeList. Much more efficient!
+
+        * loader/cache/CachedSVGDocument.cpp:
+        (WebCore::CachedSVGDocument::finishLoading): Use decodeAndFlush.
+        * loader/cache/CachedScript.cpp:
+        (WebCore::CachedScript::script): Ditto.
+        * loader/cache/CachedXSLStyleSheet.cpp:
+        (WebCore::CachedXSLStyleSheet::finishLoading): Ditto.
+        * page/Page.cpp:
+        (WebCore::Page::userStyleSheet): Ditto.
+
 2014-03-20  Darin Adler  <[email protected]>
 
         Remove a couple of unused functions from CSSOMUtils

Modified: trunk/Source/WebCore/WebCore.exp.in (166045 => 166046)


--- trunk/Source/WebCore/WebCore.exp.in	2014-03-21 06:51:18 UTC (rev 166045)
+++ trunk/Source/WebCore/WebCore.exp.in	2014-03-21 07:12:07 UTC (rev 166046)
@@ -2017,11 +2017,6 @@
 _wkSignalCFReadStreamError
 _wkSignalCFReadStreamHasBytes
 
-#if !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES) && PLATFORM(MAC)
-__ZN7WebCore7IntSizeC1ERK7_NSSize
-__ZNK7WebCore7IntSizecv7_NSSizeEv
-#endif
-
 #if !defined(NDEBUG)
 __ZN7WebCore14SQLiteDatabase22disableThreadingChecksEv
 __ZN7WebCore24NoEventDispatchAssertion7s_countE
@@ -2146,6 +2141,7 @@
 __ZN7WebCore17ScrollbarThemeMac24removeOverhangAreaShadowEP7CALayer
 __ZN7WebCore17ScrollbarThemeMac27setUpOverhangAreaBackgroundEP7CALayerRKNS_5ColorE
 __ZN7WebCore17ScrollbarThemeMac28removeOverhangAreaBackgroundEP7CALayer
+__ZN7WebCore19TextResourceDecoder14decodeAndFlushEPKcm
 __ZN7WebCore19applicationIsSafariEv
 __ZN7WebCore20PlatformEventFactory24createPlatformMouseEventEP7NSEventP6NSView
 __ZN7WebCore20PlatformEventFactory27createPlatformKeyboardEventEP7NSEvent
@@ -2315,6 +2311,11 @@
 _wkWindowSetScaledFrame
 #endif
 
+#if PLATFORM(MAC) && !defined(NSGEOMETRY_TYPES_SAME_AS_CGGEOMETRY_TYPES)
+__ZN7WebCore7IntSizeC1ERK7_NSSize
+__ZNK7WebCore7IntSizecv7_NSSizeEv
+#endif
+
 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
 __ZN7WebCore24TextAlternativeWithRangeC1EP18NSTextAlternatives8_NSRange
 __ZN7WebCore27AlternativeTextUIController15addAlternativesERKN3WTF9RetainPtrI18NSTextAlternativesEE

Modified: trunk/Source/WebCore/fileapi/FileReaderLoader.cpp (166045 => 166046)


--- trunk/Source/WebCore/fileapi/FileReaderLoader.cpp	2014-03-21 06:51:18 UTC (rev 166045)
+++ trunk/Source/WebCore/fileapi/FileReaderLoader.cpp	2014-03-21 07:12:07 UTC (rev 166046)
@@ -316,15 +316,12 @@
     // requirement in order to be consistent with how WebKit decodes the web content: always has the BOM override the
     // provided encoding.     
     // FIXME: consider supporting incremental decoding to improve the perf.
-    StringBuilder builder;
     if (!m_decoder)
         m_decoder = TextResourceDecoder::create("text/plain", m_encoding.isValid() ? m_encoding : UTF8Encoding());
-    builder.append(m_decoder->decode(static_cast<const char*>(m_rawData->data()), m_bytesLoaded));
-
     if (isCompleted())
-        builder.append(m_decoder->flush());
-
-    m_stringResult = builder.toString();
+        m_stringResult = m_decoder->decodeAndFlush(static_cast<const char*>(m_rawData->data()), m_bytesLoaded);
+    else
+        m_stringResult = m_decoder->decode(static_cast<const char*>(m_rawData->data()), m_bytesLoaded);
 }
 
 void FileReaderLoader::convertToDataURL()

Modified: trunk/Source/WebCore/inspector/InspectorPageAgent.cpp (166045 => 166046)


--- trunk/Source/WebCore/inspector/InspectorPageAgent.cpp	2014-03-21 06:51:18 UTC (rev 166045)
+++ trunk/Source/WebCore/inspector/InspectorPageAgent.cpp	2014-03-21 07:12:07 UTC (rev 166046)
@@ -186,8 +186,7 @@
             // We show content for raw resources only for certain mime types (text, html and xml). Otherwise decoder will be null.
             if (!decoder)
                 return false;
-            String content = decoder->decode(buffer->data(), buffer->size());
-            *result = content + decoder->flush();
+            *result = decoder->decodeAndFlush(buffer->data(), buffer->size());
             return true;
         }
         default:

Modified: trunk/Source/WebCore/inspector/NetworkResourcesData.cpp (166045 => 166046)


--- trunk/Source/WebCore/inspector/NetworkResourcesData.cpp	2014-03-21 06:51:18 UTC (rev 166045)
+++ trunk/Source/WebCore/inspector/NetworkResourcesData.cpp	2014-03-21 07:12:07 UTC (rev 166046)
@@ -135,8 +135,7 @@
 {
     ASSERT(!hasContent());
     size_t dataLength = m_dataBuffer->size();
-    m_content = m_decoder->decode(m_dataBuffer->data(), m_dataBuffer->size());
-    m_content.append(m_decoder->flush());
+    m_content = m_decoder->decodeAndFlush(m_dataBuffer->data(), m_dataBuffer->size());
     m_dataBuffer = nullptr;
     return contentSizeInBytes(m_content) - dataLength;
 }

Modified: trunk/Source/WebCore/loader/TextResourceDecoder.cpp (166045 => 166046)


--- trunk/Source/WebCore/loader/TextResourceDecoder.cpp	2014-03-21 06:51:18 UTC (rev 166045)
+++ trunk/Source/WebCore/loader/TextResourceDecoder.cpp	2014-03-21 07:12:07 UTC (rev 166046)
@@ -663,4 +663,10 @@
     return result;
 }
 
+String TextResourceDecoder::decodeAndFlush(const char* data, size_t length)
+{
+    String decoded = decode(data, length);
+    return decoded + flush();
 }
+
+}

Modified: trunk/Source/WebCore/loader/TextResourceDecoder.h (166045 => 166046)


--- trunk/Source/WebCore/loader/TextResourceDecoder.h	2014-03-21 06:51:18 UTC (rev 166045)
+++ trunk/Source/WebCore/loader/TextResourceDecoder.h	2014-03-21 07:12:07 UTC (rev 166046)
@@ -55,6 +55,8 @@
     String decode(const char* data, size_t length);
     String flush();
 
+    String decodeAndFlush(const char* data, size_t length);
+
     void setHintEncoding(const TextResourceDecoder* hintDecoder)
     {
         // hintEncoding is for use with autodetection, which should be 

Modified: trunk/Source/WebCore/loader/appcache/ManifestParser.cpp (166045 => 166046)


--- trunk/Source/WebCore/loader/appcache/ManifestParser.cpp	2014-03-21 06:51:18 UTC (rev 166045)
+++ trunk/Source/WebCore/loader/appcache/ManifestParser.cpp	2014-03-21 07:12:07 UTC (rev 166046)
@@ -43,9 +43,7 @@
 
     Mode mode = Explicit;
 
-    RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("text/cache-manifest", "UTF-8");
-    String s = decoder->decode(data, length);
-    s.append(decoder->flush());
+    String s = TextResourceDecoder::create("text/cache-manifest", "UTF-8")->decodeAndFlush(data, length);
     
     // Look for the magic signature: "^\xFEFF?CACHE MANIFEST[ \t]?" (the BOM is removed by TextResourceDecoder).
     // Example: "CACHE MANIFEST #comment" is a valid signature.

Modified: trunk/Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp (166045 => 166046)


--- trunk/Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp	2014-03-21 06:51:18 UTC (rev 166045)
+++ trunk/Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp	2014-03-21 07:12:07 UTC (rev 166046)
@@ -88,9 +88,7 @@
         return m_decodedSheetText;
     
     // Don't cache the decoded text, regenerating is cheap and it can use quite a bit of memory
-    String sheetText = m_decoder->decode(m_data->data(), m_data->size());
-    sheetText.append(m_decoder->flush());
-    return sheetText;
+    return m_decoder->decodeAndFlush(m_data->data(), m_data->size());
 }
 
 void CachedCSSStyleSheet::finishLoading(ResourceBuffer* data)
@@ -98,10 +96,8 @@
     m_data = data;
     setEncodedSize(m_data.get() ? m_data->size() : 0);
     // Decode the data to find out the encoding and keep the sheet text around during checkNotify()
-    if (m_data) {
-        m_decodedSheetText = m_decoder->decode(m_data->data(), m_data->size());
-        m_decodedSheetText.append(m_decoder->flush());
-    }
+    if (m_data)
+        m_decodedSheetText = m_decoder->decodeAndFlush(m_data->data(), m_data->size());
     setLoading(false);
     checkNotify();
     // Clear the decoded text as it is unlikely to be needed immediately again and is cheap to regenerate.

Modified: trunk/Source/WebCore/loader/cache/CachedFont.cpp (166045 => 166046)


--- trunk/Source/WebCore/loader/cache/CachedFont.cpp	2014-03-21 06:51:18 UTC (rev 166045)
+++ trunk/Source/WebCore/loader/cache/CachedFont.cpp	2014-03-21 07:12:07 UTC (rev 166046)
@@ -36,6 +36,7 @@
 #include "ResourceBuffer.h"
 #include "SharedBuffer.h"
 #include "TextResourceDecoder.h"
+#include "TypedElementDescendantIterator.h"
 #include "WOFFFileFormat.h"
 #include <wtf/Vector.h>
 
@@ -129,52 +130,33 @@
 }
 
 #if ENABLE(SVG_FONTS)
+
 bool CachedFont::ensureSVGFontData()
 {
     if (!m_externalSVGDocument && !errorOccurred() && !isLoading() && m_data) {
-        m_externalSVGDocument = SVGDocument::create(0, URL());
-
+        m_externalSVGDocument = SVGDocument::create(nullptr, URL());
         RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("application/xml");
-        String svgSource = decoder->decode(m_data->data(), m_data->size());
-        svgSource.append(decoder->flush());
-        
-        m_externalSVGDocument->setContent(svgSource);
-        
+        m_externalSVGDocument->setContent(decoder->decodeAndFlush(m_data->data(), m_data->size()));
         if (decoder->sawError())
-            m_externalSVGDocument = 0;
+            m_externalSVGDocument = nullptr;
     }
-
     return m_externalSVGDocument;
 }
 
 SVGFontElement* CachedFont::getSVGFontById(const String& fontName) const
 {
-    RefPtr<NodeList> list = m_externalSVGDocument->getElementsByTagNameNS(SVGNames::fontTag.namespaceURI(), SVGNames::fontTag.localName());
-    if (!list)
-        return 0;
+    auto elements = descendantsOfType<SVGFontElement>(*m_externalSVGDocument);
 
-    unsigned listLength = list->length();
-    if (!listLength)
-        return 0;
-
-#ifndef NDEBUG
-    for (unsigned i = 0; i < listLength; ++i) {
-        ASSERT(list->item(i));
-        ASSERT(isSVGFontElement(list->item(i)));
-    }
-#endif
-
     if (fontName.isEmpty())
-        return toSVGFontElement(list->item(0));
+        return elements.first();
 
-    for (unsigned i = 0; i < listLength; ++i) {
-        SVGFontElement* element = toSVGFontElement(list->item(i));
-        if (element->getIdAttribute() == fontName)
-            return element;
+    for (auto& element : elements) {
+        if (element.getIdAttribute() == fontName)
+            return &element;
     }
-
-    return 0;
+    return nullptr;
 }
+
 #endif
 
 void CachedFont::allClientsRemoved()

Modified: trunk/Source/WebCore/loader/cache/CachedSVGDocument.cpp (166045 => 166046)


--- trunk/Source/WebCore/loader/cache/CachedSVGDocument.cpp	2014-03-21 06:51:18 UTC (rev 166045)
+++ trunk/Source/WebCore/loader/cache/CachedSVGDocument.cpp	2014-03-21 07:12:07 UTC (rev 166046)
@@ -54,12 +54,9 @@
 void CachedSVGDocument::finishLoading(ResourceBuffer* data)
 {
     if (data) {
-        StringBuilder decodedText;
-        decodedText.append(m_decoder->decode(data->data(), data->size()));
-        decodedText.append(m_decoder->flush());
         // We don't need to create a new frame because the new document belongs to the parent UseElement.
-        m_document = SVGDocument::create(0, response().url());
-        m_document->setContent(decodedText.toString());
+        m_document = SVGDocument::create(nullptr, response().url());
+        m_document->setContent(m_decoder->decodeAndFlush(data->data(), data->size()));
     }
     CachedResource::finishLoading(data);
 }

Modified: trunk/Source/WebCore/loader/cache/CachedScript.cpp (166045 => 166046)


--- trunk/Source/WebCore/loader/cache/CachedScript.cpp	2014-03-21 06:51:18 UTC (rev 166045)
+++ trunk/Source/WebCore/loader/cache/CachedScript.cpp	2014-03-21 07:12:07 UTC (rev 166046)
@@ -73,8 +73,7 @@
     ASSERT(!isPurgeable());
 
     if (!m_script && m_data) {
-        m_script = m_decoder->decode(m_data->data(), encodedSize());
-        m_script.append(m_decoder->flush());
+        m_script = m_decoder->decodeAndFlush(m_data->data(), encodedSize());
         setDecodedSize(m_script.sizeInBytes());
     }
     m_decodedDataDeletionTimer.restart();

Modified: trunk/Source/WebCore/loader/cache/CachedXSLStyleSheet.cpp (166045 => 166046)


--- trunk/Source/WebCore/loader/cache/CachedXSLStyleSheet.cpp	2014-03-21 06:51:18 UTC (rev 166045)
+++ trunk/Source/WebCore/loader/cache/CachedXSLStyleSheet.cpp	2014-03-21 07:12:07 UTC (rev 166046)
@@ -67,10 +67,8 @@
 {
     m_data = data;
     setEncodedSize(m_data.get() ? m_data->size() : 0);
-    if (m_data.get()) {
-        m_sheet = m_decoder->decode(m_data->data(), encodedSize());
-        m_sheet.append(m_decoder->flush());
-    }
+    if (m_data.get())
+        m_sheet = m_decoder->decodeAndFlush(m_data->data(), encodedSize());
     setLoading(false);
     checkNotify();
 }

Modified: trunk/Source/WebCore/page/Page.cpp (166045 => 166046)


--- trunk/Source/WebCore/page/Page.cpp	2014-03-21 06:51:18 UTC (rev 166045)
+++ trunk/Source/WebCore/page/Page.cpp	2014-03-21 07:12:07 UTC (rev 166046)
@@ -924,9 +924,7 @@
     if (!data)
         return m_userStyleSheet;
 
-    RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("text/css");
-    m_userStyleSheet = decoder->decode(data->data(), data->size());
-    m_userStyleSheet.append(decoder->flush());
+    m_userStyleSheet = TextResourceDecoder::create("text/css")->decodeAndFlush(data->data(), data->size());
 
     return m_userStyleSheet;
 }

Modified: trunk/Source/WebKit/mac/ChangeLog (166045 => 166046)


--- trunk/Source/WebKit/mac/ChangeLog	2014-03-21 06:51:18 UTC (rev 166045)
+++ trunk/Source/WebKit/mac/ChangeLog	2014-03-21 07:12:07 UTC (rev 166046)
@@ -1,3 +1,13 @@
+2014-03-21  Darin Adler  <[email protected]>
+
+        Add a combined decodeAndFlush to TextResourceDecoder
+        https://bugs.webkit.org/show_bug.cgi?id=130560
+
+        Reviewed by Andreas Kling.
+
+        * WebView/WebView.mm:
+        (+[WebView _decodeData:]): Use decodeAndFlush.
+
 2014-03-20  Anders Carlsson  <[email protected]>
 
         Fix build.

Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (166045 => 166046)


--- trunk/Source/WebKit/mac/WebView/WebView.mm	2014-03-21 06:51:18 UTC (rev 166045)
+++ trunk/Source/WebKit/mac/WebView/WebView.mm	2014-03-21 07:12:07 UTC (rev 166046)
@@ -2759,10 +2759,7 @@
 + (NSString *)_decodeData:(NSData *)data
 {
     HTMLNames::init(); // this method is used for importing bookmarks at startup, so HTMLNames are likely to be uninitialized yet
-    RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("text/html"); // bookmark files are HTML
-    String result = decoder->decode(static_cast<const char*>([data bytes]), [data length]);
-    result.append(decoder->flush());
-    return result;
+    return TextResourceDecoder::create("text/html")->decodeAndFlush(static_cast<const char*>([data bytes]), [data length]); // bookmark files are HTML
 }
 
 - (void)_pushPerformingProgrammaticFocus
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to