Changeset 31807 in webkit for trunk/JavaScriptCore/wtf/Vector.h


Ignore:
Timestamp:
Apr 11, 2008, 12:37:33 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Geoff.

https://bugs.webkit.org/show_bug.cgi?id=18402
REGRESSION: visited element handling is incorrect in nested join/toString calls

No change on SunSpider total, possibly a tiny improvement (about 0.1%).

Test: fast/js/array-tostring-and-join.html

  • kjs/JSGlobalObject.h: (KJS::JSGlobalObject::visitedElements): Store visited elements HashSet here, making it common to toString/toLocalizedString/join again.
  • kjs/array_object.cpp: (KJS::arrayProtoFuncToString): (KJS::arrayProtoFuncToLocaleString): (KJS::arrayProtoFuncJoin): Got rid of static variables. Replaced UString with Vector to avoid O(n2) behavior and regain performance.
  • wtf/Vector.h: (WTF::::resize): (WTF::::grow): (WTF::::reserveCapacity): (WTF::::append): (WTF::::insert): Added null checks, so that Vector methods don't crash when out of memory. The caller should check that data pointer is not null before proceeding.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/Vector.h

    r31062 r31807  
    629629            if (size > capacity())
    630630                expandCapacity(size);
    631             TypeOperations::initialize(end(), begin() + size);
     631            if (begin())
     632                TypeOperations::initialize(end(), begin() + size);
    632633        }
    633634       
     
    649650        if (size > capacity())
    650651            expandCapacity(size);
    651         TypeOperations::initialize(end(), begin() + size);
     652        if (begin())
     653            TypeOperations::initialize(end(), begin() + size);
    652654        m_size = size;
    653655    }
     
    661663        T* oldEnd = end();
    662664        m_buffer.allocateBuffer(newCapacity);
    663         TypeOperations::move(oldBuffer, oldEnd, begin());
     665        if (begin())
     666            TypeOperations::move(oldBuffer, oldEnd, begin());
    664667        m_buffer.deallocateBuffer(oldBuffer);
    665668    }
     
    692695    {
    693696        size_t newSize = m_size + dataSize;
    694         if (newSize > capacity())
     697        if (newSize > capacity()) {
    695698            data = expandCapacity(newSize, data);
     699            if (!begin())
     700                return;
     701        }
    696702        T* dest = end();
    697703        for (size_t i = 0; i < dataSize; ++i)
     
    704710    {
    705711        const U* ptr = &val;
    706         if (size() == capacity())
     712        if (size() == capacity()) {
    707713            ptr = expandCapacity(size() + 1, ptr);
     714            if (!begin())
     715                return;
     716        }
    708717           
    709718#if COMPILER(MSVC7)
     
    744753        ASSERT(position <= size());
    745754        size_t newSize = m_size + dataSize;
    746         if (newSize > capacity())
     755        if (newSize > capacity()) {
    747756            data = expandCapacity(newSize, data);
     757            if (!begin())
     758                return;
     759        }
    748760        T* spot = begin() + position;
    749761        TypeOperations::moveOverlapping(spot, end(), spot + dataSize);
     
    758770        ASSERT(position <= size());
    759771        const U* data = &val;
    760         if (size() == capacity())
     772        if (size() == capacity()) {
    761773            data = expandCapacity(size() + 1, data);
     774            if (!begin())
     775                return;
     776        }
    762777        T* spot = begin() + position;
    763778        TypeOperations::moveOverlapping(spot, end(), spot + 1);
Note: See TracChangeset for help on using the changeset viewer.