Changeset 156492 in webkit


Ignore:
Timestamp:
Sep 26, 2013 1:44:02 PM (11 years ago)
Author:
andersca@apple.com
Message:

Change a couple of HashMap value types from OwnPtr to std::unique_ptr
https://bugs.webkit.org/show_bug.cgi?id=121973

Reviewed by Andreas Kling.

Source/JavaScriptCore:

  • API/JSClassRef.cpp:

(OpaqueJSClassContextData::OpaqueJSClassContextData):
(OpaqueJSClass::contextData):

  • API/JSClassRef.h:
  • bytecode/SamplingTool.h:
  • ftl/FTLAbstractHeap.h:
  • parser/Parser.cpp:

(JSC::::parseFunctionInfo):

  • parser/SourceProviderCache.cpp:

(JSC::SourceProviderCache::add):

  • parser/SourceProviderCache.h:
  • parser/SourceProviderCacheItem.h:

(JSC::SourceProviderCacheItem::create):

  • profiler/ProfilerCompilation.cpp:

(JSC::Profiler::Compilation::executionCounterFor):
(JSC::Profiler::Compilation::toJS):

  • profiler/ProfilerCompilation.h:
  • runtime/JSGlobalObject.h:

Source/WTF:

  • wtf/RefPtrHashMap.h:

Add a missing std::forward.

  • wtf/StdLibExtras.h:

(std::make_unique):
Add more overloads.

Location:
trunk/Source
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSClassRef.cpp

    r156469 r156492  
    6767            String valueName = String::fromUTF8(staticValue->name);
    6868            if (!valueName.isNull())
    69                 m_staticValues->set(valueName.impl(), adoptPtr(new StaticValueEntry(staticValue->getProperty, staticValue->setProperty, staticValue->attributes, valueName)));
     69                m_staticValues->set(valueName.impl(), std::make_unique<StaticValueEntry>(staticValue->getProperty, staticValue->setProperty, staticValue->attributes, valueName));
    7070            ++staticValue;
    7171        }
     
    7777            String functionName = String::fromUTF8(staticFunction->name);
    7878            if (!functionName.isNull())
    79                 m_staticFunctions->set(functionName.impl(), adoptPtr(new StaticFunctionEntry(staticFunction->callAsFunction, staticFunction->attributes)));
     79                m_staticFunctions->set(functionName.impl(), std::make_unique<StaticFunctionEntry>(staticFunction->callAsFunction, staticFunction->attributes));
    8080            ++staticFunction;
    8181        }
     
    132132{
    133133    if (jsClass->m_staticValues) {
    134         staticValues = adoptPtr(new OpaqueJSClassStaticValuesTable);
     134        staticValues = std::make_unique<OpaqueJSClassStaticValuesTable>();
    135135        OpaqueJSClassStaticValuesTable::const_iterator end = jsClass->m_staticValues->end();
    136136        for (OpaqueJSClassStaticValuesTable::const_iterator it = jsClass->m_staticValues->begin(); it != end; ++it) {
    137137            ASSERT(!it->key->isIdentifier());
    138138            String valueName = it->key->isolatedCopy();
    139             staticValues->add(valueName.impl(), adoptPtr(new StaticValueEntry(it->value->getProperty, it->value->setProperty, it->value->attributes, valueName)));
     139            staticValues->add(valueName.impl(), std::make_unique<StaticValueEntry>(it->value->getProperty, it->value->setProperty, it->value->attributes, valueName));
    140140        }
    141141    }
    142142
    143143    if (jsClass->m_staticFunctions) {
    144         staticFunctions = adoptPtr(new OpaqueJSClassStaticFunctionsTable);
     144        staticFunctions = std::make_unique<OpaqueJSClassStaticFunctionsTable>();
    145145        OpaqueJSClassStaticFunctionsTable::const_iterator end = jsClass->m_staticFunctions->end();
    146146        for (OpaqueJSClassStaticFunctionsTable::const_iterator it = jsClass->m_staticFunctions->begin(); it != end; ++it) {
    147147            ASSERT(!it->key->isIdentifier());
    148             staticFunctions->add(it->key->isolatedCopy(), adoptPtr(new StaticFunctionEntry(it->value->callAsFunction, it->value->attributes)));
     148            staticFunctions->add(it->key->isolatedCopy(), std::make_unique<StaticFunctionEntry>(it->value->callAsFunction, it->value->attributes));
    149149        }
    150150    }
     
    153153OpaqueJSClassContextData& OpaqueJSClass::contextData(ExecState* exec)
    154154{
    155     OwnPtr<OpaqueJSClassContextData>& contextData = exec->lexicalGlobalObject()->opaqueJSClassData().add(this, nullptr).iterator->value;
     155    std::unique_ptr<OpaqueJSClassContextData>& contextData = exec->lexicalGlobalObject()->opaqueJSClassData().add(this, nullptr).iterator->value;
    156156    if (!contextData)
    157         contextData = adoptPtr(new OpaqueJSClassContextData(exec->vm(), this));
     157        contextData = std::make_unique<OpaqueJSClassContextData>(exec->vm(), this);
    158158    return *contextData;
    159159}
  • trunk/Source/JavaScriptCore/API/JSClassRef.h

    r153547 r156492  
    6060};
    6161
    62 typedef HashMap<RefPtr<StringImpl>, OwnPtr<StaticValueEntry> > OpaqueJSClassStaticValuesTable;
    63 typedef HashMap<RefPtr<StringImpl>, OwnPtr<StaticFunctionEntry> > OpaqueJSClassStaticFunctionsTable;
     62typedef HashMap<RefPtr<StringImpl>, std::unique_ptr<StaticValueEntry>> OpaqueJSClassStaticValuesTable;
     63typedef HashMap<RefPtr<StringImpl>, std::unique_ptr<StaticFunctionEntry>> OpaqueJSClassStaticFunctionsTable;
    6464
    6565struct OpaqueJSClass;
     
    8080    RefPtr<OpaqueJSClass> m_class;
    8181
    82     OwnPtr<OpaqueJSClassStaticValuesTable> staticValues;
    83     OwnPtr<OpaqueJSClassStaticFunctionsTable> staticFunctions;
     82    std::unique_ptr<OpaqueJSClassStaticValuesTable> staticValues;
     83    std::unique_ptr<OpaqueJSClassStaticFunctionsTable> staticFunctions;
    8484    JSC::Weak<JSC::JSObject> cachedPrototype;
    8585};
  • trunk/Source/JavaScriptCore/ChangeLog

    r156490 r156492  
     12013-09-26  Anders Carlsson  <andersca@apple.com>
     2
     3        Change a couple of HashMap value types from OwnPtr to std::unique_ptr
     4        https://bugs.webkit.org/show_bug.cgi?id=121973
     5
     6        Reviewed by Andreas Kling.
     7
     8        * API/JSClassRef.cpp:
     9        (OpaqueJSClassContextData::OpaqueJSClassContextData):
     10        (OpaqueJSClass::contextData):
     11        * API/JSClassRef.h:
     12        * bytecode/SamplingTool.h:
     13        * ftl/FTLAbstractHeap.h:
     14        * parser/Parser.cpp:
     15        (JSC::::parseFunctionInfo):
     16        * parser/SourceProviderCache.cpp:
     17        (JSC::SourceProviderCache::add):
     18        * parser/SourceProviderCache.h:
     19        * parser/SourceProviderCacheItem.h:
     20        (JSC::SourceProviderCacheItem::create):
     21        * profiler/ProfilerCompilation.cpp:
     22        (JSC::Profiler::Compilation::executionCounterFor):
     23        (JSC::Profiler::Compilation::toJS):
     24        * profiler/ProfilerCompilation.h:
     25        * runtime/JSGlobalObject.h:
     26
    1272013-09-26  Mark Lam  <mark.lam@apple.com>
    228
  • trunk/Source/JavaScriptCore/bytecode/SamplingTool.h

    r148696 r156492  
    212212    };
    213213
    214     typedef HashMap<ScriptExecutable*, OwnPtr<ScriptSampleRecord> > ScriptSampleRecordMap;
     214    typedef HashMap<ScriptExecutable*, std::unique_ptr<ScriptSampleRecord>> ScriptSampleRecordMap;
    215215
    216216    class SamplingThread {
  • trunk/Source/JavaScriptCore/ftl/FTLAbstractHeap.h

    r155251 r156492  
    178178        static bool isDeletedValue(ptrdiff_t value) { return value == 1; }
    179179    };
    180     typedef HashMap<ptrdiff_t, OwnPtr<AbstractField>, WTF::IntHash<ptrdiff_t>, WithoutZeroOrOneHashTraits> MapType;
     180    typedef HashMap<ptrdiff_t, std::unique_ptr<AbstractField>, WTF::IntHash<ptrdiff_t>, WithoutZeroOrOneHashTraits> MapType;
    181181   
    182182    OwnPtr<MapType> m_largeIndices;
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r156480 r156492  
    996996    // Any future reparsing can then skip the function.
    997997    static const int minimumFunctionLengthToCache = 16;
    998     OwnPtr<SourceProviderCacheItem> newInfo;
     998    std::unique_ptr<SourceProviderCacheItem> newInfo;
    999999    int functionLength = closeBraceOffset - openBraceOffset;
    10001000    if (TreeBuilder::CanUseFunctionCache && m_functionCache && functionLength > minimumFunctionLengthToCache) {
     
    10141014   
    10151015    if (newInfo)
    1016         m_functionCache->add(openBraceOffset, newInfo.release());
     1016        m_functionCache->add(openBraceOffset, std::move(newInfo));
    10171017   
    10181018    next();
  • trunk/Source/JavaScriptCore/parser/SourceProviderCache.cpp

    r143279 r156492  
    3939}
    4040
    41 void SourceProviderCache::add(int sourcePosition, PassOwnPtr<SourceProviderCacheItem> item)
     41void SourceProviderCache::add(int sourcePosition, std::unique_ptr<SourceProviderCacheItem> item)
    4242{
    43     m_map.add(sourcePosition, item);
     43    m_map.add(sourcePosition, std::move(item));
    4444}
    4545
  • trunk/Source/JavaScriptCore/parser/SourceProviderCache.h

    r143279 r156492  
    4242
    4343    JS_EXPORT_PRIVATE void clear();
    44     void add(int sourcePosition, PassOwnPtr<SourceProviderCacheItem>);
     44    void add(int sourcePosition, std::unique_ptr<SourceProviderCacheItem>);
    4545    const SourceProviderCacheItem* get(int sourcePosition) const { return m_map.get(sourcePosition); }
    4646
    4747private:
    48     HashMap<int, OwnPtr<SourceProviderCacheItem> > m_map;
     48    HashMap<int, std::unique_ptr<SourceProviderCacheItem>> m_map;
    4949};
    5050
  • trunk/Source/JavaScriptCore/parser/SourceProviderCacheItem.h

    r152494 r156492  
    5454    WTF_MAKE_FAST_ALLOCATED;
    5555public:
    56     static PassOwnPtr<SourceProviderCacheItem> create(const SourceProviderCacheItemCreationParameters&);
     56    static std::unique_ptr<SourceProviderCacheItem> create(const SourceProviderCacheItemCreationParameters&);
    5757    ~SourceProviderCacheItem();
    5858
     
    9999}
    100100
    101 inline PassOwnPtr<SourceProviderCacheItem> SourceProviderCacheItem::create(const SourceProviderCacheItemCreationParameters& parameters)
     101inline std::unique_ptr<SourceProviderCacheItem> SourceProviderCacheItem::create(const SourceProviderCacheItemCreationParameters& parameters)
    102102{
    103103    size_t variableCount = parameters.writtenVariables.size() + parameters.usedVariables.size();
    104104    size_t objectSize = sizeof(SourceProviderCacheItem) + sizeof(StringImpl*) * variableCount;
    105105    void* slot = fastMalloc(objectSize);
    106     return adoptPtr(new (slot) SourceProviderCacheItem(parameters));
     106    return std::unique_ptr<SourceProviderCacheItem>(new (slot) SourceProviderCacheItem(parameters));
    107107}
    108108
  • trunk/Source/JavaScriptCore/profiler/ProfilerCompilation.cpp

    r148696 r156492  
    7070ExecutionCounter* Compilation::executionCounterFor(const OriginStack& origin)
    7171{
    72     HashMap<OriginStack, OwnPtr<ExecutionCounter> >::iterator iter = m_counters.find(origin);
    73     if (iter != m_counters.end())
    74         return iter->value.get();
    75    
    76     OwnPtr<ExecutionCounter> counter = adoptPtr(new ExecutionCounter());
    77     ExecutionCounter* result = counter.get();
    78     m_counters.add(origin, counter.release());
    79     return result;
     72    std::unique_ptr<ExecutionCounter>& counter = m_counters.add(origin, nullptr).iterator->value;
     73    if (!counter)
     74        counter = std::make_unique<ExecutionCounter>();
     75
     76    return counter.get();
    8077}
    8178
     
    109106   
    110107    JSArray* counters = constructEmptyArray(exec, 0);
    111     HashMap<OriginStack, OwnPtr<ExecutionCounter> >::const_iterator end = m_counters.end();
    112     for (HashMap<OriginStack, OwnPtr<ExecutionCounter> >::const_iterator iter = m_counters.begin(); iter != end; ++iter) {
     108    for (auto it = m_counters.begin(), end = m_counters.end(); it != end; ++it) {
    113109        JSObject* counterEntry = constructEmptyObject(exec);
    114         counterEntry->putDirect(exec->vm(), exec->propertyNames().origin, iter->key.toJS(exec));
    115         counterEntry->putDirect(exec->vm(), exec->propertyNames().executionCount, jsNumber(iter->value->count()));
     110        counterEntry->putDirect(exec->vm(), exec->propertyNames().origin, it->key.toJS(exec));
     111        counterEntry->putDirect(exec->vm(), exec->propertyNames().executionCount, jsNumber(it->value->count()));
    116112        counters->push(exec, counterEntry);
    117113    }
  • trunk/Source/JavaScriptCore/profiler/ProfilerCompilation.h

    r146548 r156492  
    7575    Vector<ProfiledBytecodes> m_profiledBytecodes;
    7676    Vector<CompiledBytecode> m_descriptions;
    77     HashMap<OriginStack, OwnPtr<ExecutionCounter> > m_counters;
     77    HashMap<OriginStack, std::unique_ptr<ExecutionCounter>> m_counters;
    7878    Vector<OSRExitSite> m_osrExitSites;
    7979    SegmentedVector<OSRExit> m_osrExits;
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r156017 r156492  
    124124class JSGlobalObject : public JSSegmentedVariableObject {
    125125private:
    126     typedef HashSet<RefPtr<OpaqueJSWeakObjectMap> > WeakMapSet;
    127     typedef HashMap<OpaqueJSClass*, OwnPtr<OpaqueJSClassContextData> > OpaqueJSClassDataMap;
     126    typedef HashSet<RefPtr<OpaqueJSWeakObjectMap>> WeakMapSet;
     127    typedef HashMap<OpaqueJSClass*, std::unique_ptr<OpaqueJSClassContextData>> OpaqueJSClassDataMap;
    128128
    129129    struct JSGlobalObjectRareData {
  • trunk/Source/WTF/ChangeLog

    r156456 r156492  
     12013-09-26  Anders Carlsson  <andersca@apple.com>
     2
     3        Change a couple of HashMap value types from OwnPtr to std::unique_ptr
     4        https://bugs.webkit.org/show_bug.cgi?id=121973
     5
     6        Reviewed by Andreas Kling.
     7
     8        * wtf/RefPtrHashMap.h:
     9        Add a missing std::forward.
     10
     11        * wtf/StdLibExtras.h:
     12        (std::make_unique):
     13        Add more overloads.
     14
    1152013-09-26  Julien Brianceau  <jbriance@cisco.com>
    216
  • trunk/Source/WTF/wtf/RefPtrHashMap.h

    r156304 r156492  
    229229    auto HashMap<RefPtr<KeyArg>, MappedArg, HashArg, KeyTraitsArg, MappedTraitsArg>::set(RawKeyType key, V&& value) -> AddResult
    230230    {
    231         AddResult result = inlineAdd(key, value);
     231        AddResult result = inlineAdd(key, std::forward<V>(value));
    232232        if (!result.isNewEntry) {
    233233            // The inlineAdd call above found an existing hash table entry; we need to set the mapped value.
  • trunk/Source/WTF/wtf/StdLibExtras.h

    r156204 r156492  
    345345        return unique_ptr<T>(new T(std::forward<A1>(a1), std::forward<A2>(a2)));
    346346    }
     347
     348    template<class T, class A1, class A2, class A3> typename _Unique_if<T>::_Single_object
     349    make_unique(A1&& a1, A1&& a2, A3&& a3)
     350    {
     351        return unique_ptr<T>(new T(std::forward<A1>(a1), std::forward<A2>(a2), std::forward<A3>(a3)));
     352    }
     353
     354    template<class T, class A1, class A2, class A3, class A4> typename _Unique_if<T>::_Single_object
     355    make_unique(A1&& a1, A1&& a2, A3&& a3, A4&& a4)
     356    {
     357        return unique_ptr<T>(new T(std::forward<A1>(a1), std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4)));
     358    }
     359
     360    template<class T, class A1, class A2, class A3, class A4, class A5> typename _Unique_if<T>::_Single_object
     361    make_unique(A1&& a1, A1&& a2, A3&& a3, A4&& a4, A5&& a5)
     362    {
     363        return unique_ptr<T>(new T(std::forward<A1>(a1), std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4), std::forward<A5>(a5)));
     364    }
     365
     366    template<class T, class A1, class A2, class A3, class A4, class A5, class A6> typename _Unique_if<T>::_Single_object
     367    make_unique(A1&& a1, A1&& a2, A3&& a3, A4&& a4, A5&& a5, A6&& a6)
     368    {
     369        return unique_ptr<T>(new T(std::forward<A1>(a1), std::forward<A2>(a2), std::forward<A3>(a3), std::forward<A4>(a4), std::forward<A5>(a5), std::forward<A6>(a6)));
     370    }
     371
    347372#endif
    348373
Note: See TracChangeset for help on using the changeset viewer.