Skip to content
Permalink
Browse files
Move WebCore/platform/text to std::unique_ptr
https://bugs.webkit.org/show_bug.cgi?id=139395

Reviewed by Darin Adler.

As a step to use std::unique_ptr<>, this patch replaces OwnPtr|PassOwnPtr with
std::unique_ptr<> | std::make_unique<>.

* dom/Document.h:
* platform/text/LineBreakIteratorPoolICU.h:
(WebCore::LineBreakIteratorPool::LineBreakIteratorPool):
(WebCore::LineBreakIteratorPool::create): Deleted.
* platform/text/LocaleICU.cpp:
(WebCore::Locale::create):
(WebCore::LocaleICU::createLabelVector):
(WebCore::createFallbackMonthLabels):
(WebCore::createFallbackAMPMLabels):
(WebCore::LocaleICU::initializeDateTimeFormat):
(WebCore::LocaleICU::shortMonthLabels):
(WebCore::LocaleICU::create): Deleted.
(WebCore::LocaleICU::standAloneMonthLabels): Deleted.
(WebCore::LocaleICU::shortStandAloneMonthLabels): Deleted.
* platform/text/LocaleICU.h:
* platform/text/LocaleNone.cpp:
(WebCore::Locale::create):
* platform/text/PlatformLocale.h:
(WebCore::Locale::createDefault):
* platform/text/TextCodecLatin1.cpp:
* platform/text/TextCodecUTF16.cpp:
* platform/text/TextEncoding.cpp:
* platform/text/mac/LocaleMac.h:
* platform/text/mac/LocaleMac.mm:
(WebCore::Locale::create):
(WebCore::LocaleMac::create):
* platform/text/mac/TextCodecMac.cpp:
* platform/text/win/LocaleWin.cpp:
(WebCore::Locale::create):
(WebCore::LocaleWin::create):
* platform/text/win/LocaleWin.h:
* platform/text/win/TextCodecWin.cpp:
(WebCore::newTextCodecWin):


Canonical link: https://commits.webkit.org/157519@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@177280 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Gyuyoung Kim committed Dec 15, 2014
1 parent 9acf60f commit 252f199122f74e66c567809869fa188c394056ff
@@ -1,3 +1,47 @@
2014-12-15 Gyuyoung Kim <gyuyoung.kim@samsung.com>

Move WebCore/platform/text to std::unique_ptr
https://bugs.webkit.org/show_bug.cgi?id=139395

Reviewed by Darin Adler.

As a step to use std::unique_ptr<>, this patch replaces OwnPtr|PassOwnPtr with
std::unique_ptr<> | std::make_unique<>.

* dom/Document.h:
* platform/text/LineBreakIteratorPoolICU.h:
(WebCore::LineBreakIteratorPool::LineBreakIteratorPool):
(WebCore::LineBreakIteratorPool::create): Deleted.
* platform/text/LocaleICU.cpp:
(WebCore::Locale::create):
(WebCore::LocaleICU::createLabelVector):
(WebCore::createFallbackMonthLabels):
(WebCore::createFallbackAMPMLabels):
(WebCore::LocaleICU::initializeDateTimeFormat):
(WebCore::LocaleICU::shortMonthLabels):
(WebCore::LocaleICU::create): Deleted.
(WebCore::LocaleICU::standAloneMonthLabels): Deleted.
(WebCore::LocaleICU::shortStandAloneMonthLabels): Deleted.
* platform/text/LocaleICU.h:
* platform/text/LocaleNone.cpp:
(WebCore::Locale::create):
* platform/text/PlatformLocale.h:
(WebCore::Locale::createDefault):
* platform/text/TextCodecLatin1.cpp:
* platform/text/TextCodecUTF16.cpp:
* platform/text/TextEncoding.cpp:
* platform/text/mac/LocaleMac.h:
* platform/text/mac/LocaleMac.mm:
(WebCore::Locale::create):
(WebCore::LocaleMac::create):
* platform/text/mac/TextCodecMac.cpp:
* platform/text/win/LocaleWin.cpp:
(WebCore::Locale::create):
(WebCore::LocaleWin::create):
* platform/text/win/LocaleWin.h:
* platform/text/win/TextCodecWin.cpp:
(WebCore::newTextCodecWin):

2014-12-15 Xavier Claessens <xavier.claessens@collabora.com>

[GStreamer] the webkitwebsrc element can stale
@@ -1677,7 +1677,7 @@ class Document : public ContainerNode, public TreeScope, public ScriptExecutionC
bool m_didDispatchViewportPropertiesChanged;
#endif

typedef HashMap<AtomicString, OwnPtr<Locale>> LocaleIdentifierToLocaleMap;
typedef HashMap<AtomicString, std::unique_ptr<Locale>> LocaleIdentifierToLocaleMap;
LocaleIdentifierToLocaleMap m_localeCache;

#if ENABLE(TEMPLATE_ELEMENT)
@@ -31,7 +31,6 @@
#include <unicode/ubrk.h>
#include <wtf/Assertions.h>
#include <wtf/HashMap.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/ThreadSpecific.h>
#include <wtf/text/AtomicString.h>
#include <wtf/text/CString.h>
@@ -42,14 +41,14 @@ namespace WebCore {
class LineBreakIteratorPool {
WTF_MAKE_NONCOPYABLE(LineBreakIteratorPool);
public:
LineBreakIteratorPool() { }

static LineBreakIteratorPool& sharedPool()
{
static WTF::ThreadSpecific<LineBreakIteratorPool>* pool = new WTF::ThreadSpecific<LineBreakIteratorPool>;
return **pool;
}

static PassOwnPtr<LineBreakIteratorPool> create() { return adoptPtr(new LineBreakIteratorPool); }

static String makeLocaleWithBreakKeyword(const AtomicString& locale, LineBreakIteratorMode mode)
{
StringBuilder localeWithKeyword;
@@ -113,8 +112,6 @@ class LineBreakIteratorPool {
}

private:
LineBreakIteratorPool() { }

static const size_t capacity = 4;

typedef std::pair<AtomicString, TextBreakIterator*> Entry;
@@ -36,17 +36,16 @@
#include <unicode/udatpg.h>
#include <unicode/uloc.h>
#include <wtf/DateMath.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/text/StringBuilder.h>

using namespace icu;
using namespace std;

namespace WebCore {

PassOwnPtr<Locale> Locale::create(const AtomicString& locale)
std::unique_ptr<Locale> Locale::create(const AtomicString& locale)
{
return LocaleICU::create(locale.string().utf8().data());
return std::make_unique<LocaleICU>(locale.string().utf8().data());
}

LocaleICU::LocaleICU(const char* locale)
@@ -73,11 +72,6 @@ LocaleICU::~LocaleICU()
#endif
}

PassOwnPtr<LocaleICU> LocaleICU::create(const char* localeString)
{
return adoptPtr(new LocaleICU(localeString));
}

String LocaleICU::decimalSymbol(UNumberFormatSymbol symbol)
{
UErrorCode status = U_ZERO_ERROR;
@@ -170,39 +164,39 @@ static String getDateFormatPattern(const UDateFormat* dateFormat)
return String::adopt(buffer);
}

PassOwnPtr<Vector<String> > LocaleICU::createLabelVector(const UDateFormat* dateFormat, UDateFormatSymbolType type, int32_t startIndex, int32_t size)
std::unique_ptr<Vector<String>> LocaleICU::createLabelVector(const UDateFormat* dateFormat, UDateFormatSymbolType type, int32_t startIndex, int32_t size)
{
if (!dateFormat)
return PassOwnPtr<Vector<String> >();
return std::make_unique<Vector<String>>();
if (udat_countSymbols(dateFormat, type) != startIndex + size)
return PassOwnPtr<Vector<String> >();
return std::make_unique<Vector<String>>();

OwnPtr<Vector<String> > labels = adoptPtr(new Vector<String>());
auto labels = std::make_unique<Vector<String>>();
labels->reserveCapacity(size);
for (int32_t i = 0; i < size; ++i) {
UErrorCode status = U_ZERO_ERROR;
int32_t length = udat_getSymbols(dateFormat, type, startIndex + i, 0, 0, &status);
if (status != U_BUFFER_OVERFLOW_ERROR)
return PassOwnPtr<Vector<String> >();
return std::make_unique<Vector<String>>();
Vector<UChar> buffer(length);
status = U_ZERO_ERROR;
udat_getSymbols(dateFormat, type, startIndex + i, buffer.data(), length, &status);
if (U_FAILURE(status))
return PassOwnPtr<Vector<String> >();
return std::make_unique<Vector<String>>();
labels->append(String::adopt(buffer));
}
return labels.release();
return WTF::move(labels);
}
#endif

#if ENABLE(DATE_AND_TIME_INPUT_TYPES)
static PassOwnPtr<Vector<String> > createFallbackMonthLabels()
static std::unique_ptr<Vector<String>> createFallbackMonthLabels()
{
OwnPtr<Vector<String> > labels = adoptPtr(new Vector<String>());
auto labels = std::make_unique<Vector<String>>();
labels->reserveCapacity(WTF_ARRAY_LENGTH(WTF::monthFullName));
for (unsigned i = 0; i < WTF_ARRAY_LENGTH(WTF::monthFullName); ++i)
labels->append(WTF::monthFullName[i]);
return labels.release();
return WTF::move(labels);
}

const Vector<String>& LocaleICU::monthLabels()
@@ -220,13 +214,13 @@ const Vector<String>& LocaleICU::monthLabels()
#endif

#if ENABLE(DATE_AND_TIME_INPUT_TYPES)
static PassOwnPtr<Vector<String> > createFallbackAMPMLabels()
static std::unique_ptr<Vector<String>> createFallbackAMPMLabels()
{
OwnPtr<Vector<String> > labels = adoptPtr(new Vector<String>());
auto labels = std::make_unique<Vector<String>>();
labels->reserveCapacity(2);
labels->append("AM");
labels->append("PM");
return labels.release();
return WTF::move(labels);
}

void LocaleICU::initializeDateTimeFormat()
@@ -251,7 +245,7 @@ void LocaleICU::initializeDateTimeFormat()
m_dateTimeFormatWithoutSeconds = getDateFormatPattern(dateTimeFormatWithoutSeconds);
udat_close(dateTimeFormatWithoutSeconds);

OwnPtr<Vector<String> > timeAMPMLabels = createLabelVector(m_mediumTimeFormat, UDAT_AM_PMS, UCAL_AM, 2);
auto timeAMPMLabels = createLabelVector(m_mediumTimeFormat, UDAT_AM_PMS, UCAL_AM, 2);
if (!timeAMPMLabels)
timeAMPMLabels = createFallbackAMPMLabels();
m_timeAMPMLabels = *timeAMPMLabels;
@@ -336,7 +330,7 @@ const Vector<String>& LocaleICU::shortMonthLabels()
if (!m_shortMonthLabels.isEmpty())
return m_shortMonthLabels;
if (initializeShortDateFormat()) {
if (OwnPtr<Vector<String> > labels = createLabelVector(m_shortDateFormat, UDAT_SHORT_MONTHS, UCAL_JANUARY, 12)) {
if (auto labels = createLabelVector(m_shortDateFormat, UDAT_SHORT_MONTHS, UCAL_JANUARY, 12)) {
m_shortMonthLabels = *labels;
return m_shortMonthLabels;
}
@@ -352,7 +346,7 @@ const Vector<String>& LocaleICU::standAloneMonthLabels()
if (!m_standAloneMonthLabels.isEmpty())
return m_standAloneMonthLabels;
if (initializeShortDateFormat()) {
if (OwnPtr<Vector<String> > labels = createLabelVector(m_shortDateFormat, UDAT_STANDALONE_MONTHS, UCAL_JANUARY, 12)) {
if (auto labels = createLabelVector(m_shortDateFormat, UDAT_STANDALONE_MONTHS, UCAL_JANUARY, 12)) {
m_standAloneMonthLabels = *labels;
return m_standAloneMonthLabels;
}
@@ -366,7 +360,7 @@ const Vector<String>& LocaleICU::shortStandAloneMonthLabels()
if (!m_shortStandAloneMonthLabels.isEmpty())
return m_shortStandAloneMonthLabels;
if (initializeShortDateFormat()) {
if (OwnPtr<Vector<String> > labels = createLabelVector(m_shortDateFormat, UDAT_STANDALONE_SHORT_MONTHS, UCAL_JANUARY, 12)) {
if (auto labels = createLabelVector(m_shortDateFormat, UDAT_STANDALONE_SHORT_MONTHS, UCAL_JANUARY, 12)) {
m_shortStandAloneMonthLabels = *labels;
return m_shortStandAloneMonthLabels;
}
@@ -36,7 +36,6 @@
#include <unicode/udat.h>
#include <unicode/unum.h>
#include <wtf/Forward.h>
#include <wtf/OwnPtr.h>
#include <wtf/text/CString.h>
#include <wtf/text/WTFString.h>

@@ -46,7 +45,7 @@ namespace WebCore {
// and LocalizedNumberICUTest.cpp.
class LocaleICU : public Locale {
public:
static PassOwnPtr<LocaleICU> create(const char* localeString);
explicit LocaleICU(const char*);
virtual ~LocaleICU();

#if ENABLE(DATE_AND_TIME_INPUT_TYPES)
@@ -65,7 +64,6 @@ class LocaleICU : public Locale {
#endif

private:
explicit LocaleICU(const char*);
String decimalSymbol(UNumberFormatSymbol);
String decimalTextAttribute(UNumberFormatTextAttribute);
virtual void initializeLocaleData() override;
@@ -77,7 +75,7 @@ class LocaleICU : public Locale {
UDateFormat* openDateFormat(UDateFormatStyle timeStyle, UDateFormatStyle dateStyle) const;

#if ENABLE(DATE_AND_TIME_INPUT_TYPES)
PassOwnPtr<Vector<String> > createLabelVector(const UDateFormat*, UDateFormatSymbolType, int32_t startIndex, int32_t size);
std::unique_ptr<Vector<String>> createLabelVector(const UDateFormat*, UDateFormatSymbolType, int32_t startIndex, int32_t size);
void initializeDateTimeFormat();
#endif

@@ -88,7 +86,7 @@ class LocaleICU : public Locale {
bool m_didCreateShortDateFormat;

#if ENABLE(DATE_AND_TIME_INPUT_TYPES)
OwnPtr<Vector<String> > m_monthLabels;
std::unique_ptr<Vector<String>> m_monthLabels;
String m_dateFormat;
String m_monthFormat;
String m_shortMonthFormat;
@@ -26,7 +26,6 @@
#include "config.h"
#include "PlatformLocale.h"
#include <wtf/DateMath.h>
#include <wtf/PassOwnPtr.h>

namespace WebCore {

@@ -56,9 +55,9 @@ class LocaleNone : public Locale {
#endif
};

PassOwnPtr<Locale> Locale::create(const AtomicString&)
std::unique_ptr<Locale> Locale::create(const AtomicString&)
{
return adoptPtr(new LocaleNone());
return std::make_unique<LocaleNone>();
}

LocaleNone::~LocaleNone()
@@ -28,7 +28,6 @@

#include "DateComponents.h"
#include "Language.h"
#include <wtf/PassOwnPtr.h>
#include <wtf/text/WTFString.h>

namespace WebCore {
@@ -41,8 +40,8 @@ class Locale {
WTF_MAKE_NONCOPYABLE(Locale);

public:
static PassOwnPtr<Locale> create(const AtomicString& localeIdentifier);
static PassOwnPtr<Locale> createDefault();
static std::unique_ptr<Locale> create(const AtomicString& localeIdentifier);
static std::unique_ptr<Locale> createDefault();

// Converts the specified number string to another number string localized
// for this Locale locale. The input string must conform to HTML
@@ -150,7 +149,7 @@ class Locale {
bool m_hasLocaleData;
};

inline PassOwnPtr<Locale> Locale::createDefault()
inline std::unique_ptr<Locale> Locale::createDefault()
{
return Locale::create(defaultLanguage());
}
@@ -27,7 +27,6 @@
#include "TextCodecLatin1.h"

#include "TextCodecASCIIFastPath.h"
#include <wtf/PassOwnPtr.h>
#include <wtf/text/CString.h>
#include <wtf/text/StringBuffer.h>
#include <wtf/text/WTFString.h>
@@ -26,7 +26,6 @@
#include "config.h"
#include "TextCodecUTF16.h"

#include <wtf/PassOwnPtr.h>
#include <wtf/text/CString.h>
#include <wtf/text/StringBuffer.h>
#include <wtf/text/WTFString.h>
@@ -31,7 +31,6 @@
#include "TextCodec.h"
#include "TextEncodingRegistry.h"
#include <unicode/unorm.h>
#include <wtf/OwnPtr.h>
#include <wtf/StdLibExtras.h>
#include <wtf/text/CString.h>
#include <wtf/text/StringView.h>
@@ -47,7 +47,7 @@ class DateComponents;

class LocaleMac : public Locale {
public:
static PassOwnPtr<LocaleMac> create(NSLocale*);
explicit LocaleMac(NSLocale*);
~LocaleMac();

#if PLATFORM(IOS)
@@ -70,7 +70,6 @@ class LocaleMac : public Locale {
#endif

private:
explicit LocaleMac(NSLocale*);
RetainPtr<NSDateFormatter> shortDateFormatter();
virtual void initializeLocaleData() override;

@@ -36,7 +36,6 @@
#include "Language.h"
#include "LocalizedStrings.h"
#include <wtf/DateMath.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/RetainPtr.h>
#include <wtf/text/StringBuilder.h>

@@ -67,9 +66,9 @@ static inline String languageFromLocale(const String& locale)
return adoptNS([[NSLocale alloc] initWithLocaleIdentifier:locale]);
}

PassOwnPtr<Locale> Locale::create(const AtomicString& locale)
std::unique_ptr<Locale> Locale::create(const AtomicString& locale)
{
return LocaleMac::create(determineLocale(locale.string()).get());
return std::make_unique<LocaleMac>(determineLocale(locale.string()).get());
}

static RetainPtr<NSDateFormatter> createDateTimeFormatter(NSLocale* locale, NSCalendar* calendar, NSDateFormatterStyle dateStyle, NSDateFormatterStyle timeStyle)
@@ -104,11 +103,6 @@ static inline String languageFromLocale(const String& locale)
{
}

PassOwnPtr<LocaleMac> LocaleMac::create(NSLocale* locale)
{
return adoptPtr(new LocaleMac(locale));
}

RetainPtr<NSDateFormatter> LocaleMac::shortDateFormatter()
{
return createDateTimeFormatter(m_locale.get(), m_gregorianCalendar.get(), NSDateFormatterShortStyle, NSDateFormatterNoStyle);
@@ -33,7 +33,6 @@
#include "CharsetData.h"
#include "ThreadGlobalData.h"
#include <wtf/Assertions.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/RetainPtr.h>
#include <wtf/Threading.h>
#include <wtf/text/CString.h>

0 comments on commit 252f199

Please sign in to comment.