Move TextCodec classes to std::unique_ptr
authorgyuyoung.kim@samsung.com <gyuyoung.kim@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Oct 2014 02:50:59 +0000 (02:50 +0000)
committergyuyoung.kim@samsung.com <gyuyoung.kim@samsung.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Oct 2014 02:50:59 +0000 (02:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137738

Reviewed by Darin Adler.

Replace uses of PassOwnPtr in code under TextCodecFoo class with std::unique_ptr.
To do this, ctor of TextCodecFoo classes is changed from private to public. Besides
related classes follow this change as well.

No new tests, no behavior change.

* html/parser/HTMLMetaCharsetParser.h:
* loader/TextResourceDecoder.cpp:
(WebCore::TextResourceDecoder::setEncoding):
(WebCore::TextResourceDecoder::flush):
* loader/TextResourceDecoder.h:
* platform/text/TextCodec.h:
* platform/text/TextCodecICU.cpp:
(WebCore::TextCodecICU::create):
* platform/text/TextCodecICU.h:
* platform/text/TextCodecLatin1.cpp:
(WebCore::newStreamingTextDecoderWindowsLatin1):
* platform/text/TextCodecUTF16.cpp:
(WebCore::newStreamingTextDecoderUTF16LE):
(WebCore::newStreamingTextDecoderUTF16BE):
* platform/text/TextCodecUTF8.cpp:
(WebCore::TextCodecUTF8::create):
* platform/text/TextCodecUTF8.h:
* platform/text/TextCodecUserDefined.cpp:
(WebCore::newStreamingTextDecoderUserDefined):
* platform/text/TextEncodingRegistry.cpp:
(WebCore::newTextCodec):
* platform/text/TextEncodingRegistry.h:
* platform/text/mac/TextCodecMac.cpp:
(WebCore::newTextCodecMac):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@174757 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/html/parser/HTMLMetaCharsetParser.h
Source/WebCore/loader/TextResourceDecoder.cpp
Source/WebCore/loader/TextResourceDecoder.h
Source/WebCore/platform/text/TextCodec.h
Source/WebCore/platform/text/TextCodecICU.cpp
Source/WebCore/platform/text/TextCodecICU.h
Source/WebCore/platform/text/TextCodecLatin1.cpp
Source/WebCore/platform/text/TextCodecUTF16.cpp
Source/WebCore/platform/text/TextCodecUTF8.cpp
Source/WebCore/platform/text/TextCodecUTF8.h
Source/WebCore/platform/text/TextCodecUserDefined.cpp
Source/WebCore/platform/text/TextEncodingRegistry.cpp
Source/WebCore/platform/text/TextEncodingRegistry.h
Source/WebCore/platform/text/mac/TextCodecMac.cpp

index d591632..4dd4c45 100644 (file)
@@ -1,3 +1,41 @@
+2014-10-15  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
+
+        Move TextCodec classes to std::unique_ptr
+        https://bugs.webkit.org/show_bug.cgi?id=137738
+
+        Reviewed by Darin Adler.
+
+        Replace uses of PassOwnPtr in code under TextCodecFoo class with std::unique_ptr.
+        To do this, ctor of TextCodecFoo classes is changed from private to public. Besides
+        related classes follow this change as well.
+
+        No new tests, no behavior change.
+
+        * html/parser/HTMLMetaCharsetParser.h:
+        * loader/TextResourceDecoder.cpp:
+        (WebCore::TextResourceDecoder::setEncoding):
+        (WebCore::TextResourceDecoder::flush):
+        * loader/TextResourceDecoder.h:
+        * platform/text/TextCodec.h:
+        * platform/text/TextCodecICU.cpp:
+        (WebCore::TextCodecICU::create):
+        * platform/text/TextCodecICU.h:
+        * platform/text/TextCodecLatin1.cpp:
+        (WebCore::newStreamingTextDecoderWindowsLatin1):
+        * platform/text/TextCodecUTF16.cpp:
+        (WebCore::newStreamingTextDecoderUTF16LE):
+        (WebCore::newStreamingTextDecoderUTF16BE):
+        * platform/text/TextCodecUTF8.cpp:
+        (WebCore::TextCodecUTF8::create):
+        * platform/text/TextCodecUTF8.h:
+        * platform/text/TextCodecUserDefined.cpp:
+        (WebCore::newStreamingTextDecoderUserDefined):
+        * platform/text/TextEncodingRegistry.cpp:
+        (WebCore::newTextCodec):
+        * platform/text/TextEncodingRegistry.h:
+        * platform/text/mac/TextCodecMac.cpp:
+        (WebCore::newTextCodecMac):
+
 2014-10-15  Dean Jackson  <dino@apple.com>
 
         [Media] Reduce style updates (painting) in controls
index 618ce7f..de028bb 100644 (file)
@@ -63,7 +63,7 @@ private:
     };
 
     std::unique_ptr<HTMLTokenizer> m_tokenizer;
-    OwnPtr<TextCodec> m_assumedCodec;
+    std::unique_ptr<TextCodec> m_assumedCodec;
     SegmentedString m_input;
     HTMLToken m_token;
     bool m_inHeadSection;
index 9802165..1daa820 100644 (file)
@@ -355,7 +355,7 @@ void TextResourceDecoder::setEncoding(const TextEncoding& encoding, EncodingSour
     else
         m_encoding = encoding;
 
-    m_codec.clear();
+    m_codec = nullptr;
     m_source = source;
 }
 
@@ -660,7 +660,7 @@ String TextResourceDecoder::flush()
 
     String result = m_codec->decode(m_buffer.data(), m_buffer.size(), true, m_contentType == XML && !m_useLenientXMLDecoding, m_sawError);
     m_buffer.clear();
-    m_codec.clear();
+    m_codec = nullptr;
     m_checkedForBOM = false; // Skip BOM again when re-decoding.
     return result;
 }
index c674711..2a92548 100644 (file)
@@ -84,7 +84,7 @@ private:
 
     ContentType m_contentType;
     TextEncoding m_encoding;
-    OwnPtr<TextCodec> m_codec;
+    std::unique_ptr<TextCodec> m_codec;
     EncodingSource m_source;
     const char* m_hintEncoding;
     Vector<char> m_buffer;
index 5ed9cc6..d9272f9 100644 (file)
@@ -78,7 +78,7 @@ namespace WebCore {
 
     typedef void (*EncodingNameRegistrar)(const char* alias, const char* name);
 
-    typedef PassOwnPtr<TextCodec> (*NewTextCodecFunction)(const TextEncoding&, const void* additionalData);
+    typedef std::unique_ptr<TextCodec> (*NewTextCodecFunction)(const TextEncoding&, const void* additionalData);
     typedef void (*TextCodecRegistrar)(const char* name, NewTextCodecFunction, const void* additionalData);
 
 } // namespace WebCore
index d98f9ac..dd6ff06 100644 (file)
@@ -66,10 +66,10 @@ static UConverter*& cachedConverterICU()
     return threadGlobalData().cachedConverterICU().converter;
 }
 
-PassOwnPtr<TextCodec> TextCodecICU::create(const TextEncoding& encoding, const void* additionalData)
+std::unique_ptr<TextCodec> TextCodecICU::create(const TextEncoding& encoding, const void* additionalData)
 {
     // Name strings are persistently kept in TextEncodingRegistry maps, so they are never deleted.
-    return adoptPtr(new TextCodecICU(encoding.name(), static_cast<const char*>(additionalData)));
+    return std::make_unique<TextCodecICU>(encoding.name(), static_cast<const char*>(additionalData));
 }
 
 void TextCodecICU::registerEncodingNames(EncodingNameRegistrar registrar)
index 6058302..8f7d673 100644 (file)
@@ -36,15 +36,16 @@ namespace WebCore {
 
     class TextCodecICU : public TextCodec {
     public:
+        static std::unique_ptr<TextCodec> create(const TextEncoding&, const void* additionalData);
+
+        TextCodecICU(const char* encoding, const char* canonicalConverterName);
+
         static void registerEncodingNames(EncodingNameRegistrar);
         static void registerCodecs(TextCodecRegistrar);
 
         virtual ~TextCodecICU();
 
     private:
-        TextCodecICU(const char* encoding, const char* canonicalConverterName);
-        static PassOwnPtr<TextCodec> create(const TextEncoding&, const void* additionalData);
-
         virtual String decode(const char*, size_t length, bool flush, bool stopOnError, bool& sawError);
         virtual CString encode(const UChar*, size_t length, UnencodableHandling);
 
index 373f226..4673be0 100644 (file)
@@ -104,9 +104,9 @@ void TextCodecLatin1::registerEncodingNames(EncodingNameRegistrar registrar)
     registrar("x-ansi", "US-ASCII");
 }
 
-static PassOwnPtr<TextCodec> newStreamingTextDecoderWindowsLatin1(const TextEncoding&, const void*)
+static std::unique_ptr<TextCodec> newStreamingTextDecoderWindowsLatin1(const TextEncoding&, const void*)
 {
-    return adoptPtr(new TextCodecLatin1);
+    return std::make_unique<TextCodecLatin1>();
 }
 
 void TextCodecLatin1::registerCodecs(TextCodecRegistrar registrar)
index d98d519..195aba4 100644 (file)
@@ -48,14 +48,14 @@ void TextCodecUTF16::registerEncodingNames(EncodingNameRegistrar registrar)
     registrar("unicodeFFFE", "UTF-16BE");
 }
 
-static PassOwnPtr<TextCodec> newStreamingTextDecoderUTF16LE(const TextEncoding&, const void*)
+static std::unique_ptr<TextCodec> newStreamingTextDecoderUTF16LE(const TextEncoding&, const void*)
 {
-    return adoptPtr(new TextCodecUTF16(true));
+    return std::make_unique<TextCodecUTF16>(true);
 }
 
-static PassOwnPtr<TextCodec> newStreamingTextDecoderUTF16BE(const TextEncoding&, const void*)
+static std::unique_ptr<TextCodec> newStreamingTextDecoderUTF16BE(const TextEncoding&, const void*)
 {
-    return adoptPtr(new TextCodecUTF16(false));
+    return std::make_unique<TextCodecUTF16>(false);
 }
 
 void TextCodecUTF16::registerCodecs(TextCodecRegistrar registrar)
index 6472f13..6b32955 100644 (file)
@@ -38,9 +38,9 @@ namespace WebCore {
 
 const int nonCharacter = -1;
 
-PassOwnPtr<TextCodec> TextCodecUTF8::create(const TextEncoding&, const void*)
+std::unique_ptr<TextCodec> TextCodecUTF8::create(const TextEncoding&, const void*)
 {
-    return adoptPtr(new TextCodecUTF8);
+    return std::make_unique<TextCodecUTF8>();
 }
 
 void TextCodecUTF8::registerEncodingNames(EncodingNameRegistrar registrar)
index ff91469..94305ce 100644 (file)
@@ -32,13 +32,16 @@ namespace WebCore {
 
 class TextCodecUTF8 : public TextCodec {
 public:
+    static std::unique_ptr<TextCodec> create(const TextEncoding&, const void*);
+    TextCodecUTF8()
+        : m_partialSequenceSize(0)
+    {
+    }
+
     static void registerEncodingNames(EncodingNameRegistrar);
     static void registerCodecs(TextCodecRegistrar);
 
 private:
-    static PassOwnPtr<TextCodec> create(const TextEncoding&, const void*);
-    TextCodecUTF8() : m_partialSequenceSize(0) { }
-
     virtual String decode(const char*, size_t length, bool flush, bool stopOnError, bool& sawError);
     virtual CString encode(const UChar*, size_t length, UnencodableHandling);
 
index d81a635..e319214 100644 (file)
@@ -27,7 +27,6 @@
 #include "TextCodecUserDefined.h"
 
 #include <stdio.h>
-#include <wtf/PassOwnPtr.h>
 #include <wtf/text/CString.h>
 #include <wtf/text/StringBuffer.h>
 #include <wtf/text/StringBuilder.h>
@@ -40,9 +39,9 @@ void TextCodecUserDefined::registerEncodingNames(EncodingNameRegistrar registrar
     registrar("x-user-defined", "x-user-defined");
 }
 
-static PassOwnPtr<TextCodec> newStreamingTextDecoderUserDefined(const TextEncoding&, const void*)
+static std::unique_ptr<TextCodec> newStreamingTextDecoderUserDefined(const TextEncoding&, const void*)
 {
-    return adoptPtr(new TextCodecUserDefined);
+    return std::make_unique<TextCodecUserDefined>();
 }
 
 void TextCodecUserDefined::registerCodecs(TextCodecRegistrar registrar)
index 86d5d2e..bc1f309 100644 (file)
@@ -292,7 +292,7 @@ static void extendTextCodecMaps()
     buildQuirksSets();
 }
 
-PassOwnPtr<TextCodec> newTextCodec(const TextEncoding& encoding)
+std::unique_ptr<TextCodec> newTextCodec(const TextEncoding& encoding)
 {
     std::lock_guard<std::mutex> lock(encodingRegistryMutex());
 
index ec0463b..e882a9a 100644 (file)
@@ -27,7 +27,6 @@
 #define TextEncodingRegistry_h
 
 #include <memory>
-#include <wtf/PassOwnPtr.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -37,7 +36,7 @@ namespace WebCore {
 
     // Use TextResourceDecoder::decode to decode resources, since it handles BOMs.
     // Use TextEncoding::encode to encode, since it takes care of normalization.
-    PassOwnPtr<TextCodec> newTextCodec(const TextEncoding&);
+    std::unique_ptr<TextCodec> newTextCodec(const TextEncoding&);
 
     // Only TextEncoding should use the following functions directly.
     const char* atomicCanonicalTextEncodingName(const char* alias);
index 56cfcfb..a16e307 100644 (file)
@@ -66,9 +66,9 @@ void TextCodecMac::registerEncodingNames(EncodingNameRegistrar registrar)
     }
 }
 
-static PassOwnPtr<TextCodec> newTextCodecMac(const TextEncoding&, const void* additionalData)
+static std::unique_ptr<TextCodec> newTextCodecMac(const TextEncoding&, const void* additionalData)
 {
-    return adoptPtr(new TextCodecMac(*static_cast<const TECTextEncodingID*>(additionalData)));
+    return std::make_unique<TextCodecMac>(*static_cast<const TECTextEncodingID*>(additionalData));
 }
 
 void TextCodecMac::registerCodecs(TextCodecRegistrar registrar)