Commit cf553561 authored by barraclough@apple.com's avatar barraclough@apple.com

https://bugs.webkit.org/show_bug.cgi?id=75140

Reviewed by Sam Weinig.

Rewrite JSArray::putSlowCase to be much cleaner & simpler.

This rewrite only significantly changes behaviour for sparse array, specifically
in how sparse arrays are reified back to vector form. This does not affect arrays
with less than 10000 entries (since these always use a vector). The more common
cases of sparse array behavior (though large sparse arrays are rare) - arrays that
always remain sparse, and arrays that are filled in reverse sequential order -
should be just as fast or faster (since reification is simpler & no longer
requires map lookups) after these changes.

Simplifying this code allows all cases of putByIndex that need to grow the vector
to do so via increaseVectorLength, which means that this method can encapsulate
the policy of determining how the vector should be grown.

No performance impact.

* runtime/JSArray.cpp:
(JSC::isDenseEnoughForVector):
    - any array of length <= MIN_SPARSE_ARRAY_INDEX is dense enough for a vector.
(JSC::JSArray::putByIndex):
    - simplify & comment.
(JSC::JSArray::putByIndexBeyondVectorLength):
    - Re-written to be much clearer & simpler.
(JSC::JSArray::increaseVectorLength):
(JSC::JSArray::increaseVectorPrefixLength):
    - add explicit checks against MAX_STORAGE_VECTOR_LENGTH, so clients do not need do so.
(JSC::JSArray::push):
    - simplify & comment.
* runtime/JSArray.h:
    - removed SparseArrayValueMap::take.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@103964 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent e67eb327
2012-01-03 Gavin Barraclough <barraclough@apple.com>
https://bugs.webkit.org/show_bug.cgi?id=75140
Reviewed by Sam Weinig.
Rewrite JSArray::putSlowCase to be much cleaner & simpler.
This rewrite only significantly changes behaviour for sparse array, specifically
in how sparse arrays are reified back to vector form. This does not affect arrays
with less than 10000 entries (since these always use a vector). The more common
cases of sparse array behavior (though large sparse arrays are rare) - arrays that
always remain sparse, and arrays that are filled in reverse sequential order -
should be just as fast or faster (since reification is simpler & no longer
requires map lookups) after these changes.
Simplifying this code allows all cases of putByIndex that need to grow the vector
to do so via increaseVectorLength, which means that this method can encapsulate
the policy of determining how the vector should be grown.
No performance impact.
* runtime/JSArray.cpp:
(JSC::isDenseEnoughForVector):
- any array of length <= MIN_SPARSE_ARRAY_INDEX is dense enough for a vector.
(JSC::JSArray::putByIndex):
- simplify & comment.
(JSC::JSArray::putByIndexBeyondVectorLength):
- Re-written to be much clearer & simpler.
(JSC::JSArray::increaseVectorLength):
(JSC::JSArray::increaseVectorPrefixLength):
- add explicit checks against MAX_STORAGE_VECTOR_LENGTH, so clients do not need do so.
(JSC::JSArray::push):
- simplify & comment.
* runtime/JSArray.h:
- removed SparseArrayValueMap::take.
2012-01-03 Gavin Barraclough <barraclough@apple.com>
Windows build fix.
This diff is collapsed.
......@@ -69,6 +69,7 @@ namespace JSC {
iterator find(unsigned);
// This should ASSERT the remove is valid (check the result of the find).
void remove(iterator it) { m_map.remove(it); }
void remove(unsigned i) { m_map.remove(i); }
// These methods do not mutate the contents of the map.
iterator notFound() { return m_map.end(); }
......@@ -79,17 +80,6 @@ namespace JSC {
const_iterator begin() const { return m_map.begin(); }
const_iterator end() const { return m_map.end(); }
// These are only used in non-SparseMode paths.
JSValue take(unsigned i)
{
ASSERT(!sparseMode());
return m_map.take(i).get();
}
void remove(unsigned i)
{
m_map.remove(i);
}
private:
Map m_map;
Flags m_flags;
......@@ -256,7 +246,7 @@ namespace JSC {
private:
bool getOwnPropertySlotSlowCase(ExecState*, unsigned propertyName, PropertySlot&);
void putSlowCase(ExecState*, unsigned propertyName, JSValue);
void putByIndexBeyondVectorLength(JSGlobalData&, unsigned propertyName, JSValue);
unsigned getNewVectorLength(unsigned desiredLength);
bool increaseVectorLength(unsigned newLength);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment