Use Vector::reserveInitialCapacity() when possible in JavaScriptCore runtime
authorbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 Apr 2013 00:43:46 +0000 (00:43 +0000)
committerbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 8 Apr 2013 00:43:46 +0000 (00:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=114111

Reviewed by Andreas Kling.

Almost all the code was already using Vector::reserveInitialCapacity()
and Vector::uncheckedAppend(). Fix the remaining parts.

* runtime/ArgList.h:
(MarkedArgumentBuffer): The type VectorType is unused.

* runtime/ArrayPrototype.cpp:
(JSC::arrayProtoFuncSort):
Move the variable closer to where it is needed.

* runtime/JSArray.cpp:
(JSC::JSArray::setLengthWithArrayStorage):
* runtime/JSObject.cpp:
(JSC::JSObject::getOwnPropertyNames):

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/ArgList.h
Source/JavaScriptCore/runtime/ArrayPrototype.cpp
Source/JavaScriptCore/runtime/JSArray.cpp
Source/JavaScriptCore/runtime/JSObject.cpp

index cc92c76..8aee092 100644 (file)
@@ -1,3 +1,25 @@
+2013-04-07  Benjamin Poulain  <benjamin@webkit.org>
+
+        Use Vector::reserveInitialCapacity() when possible in JavaScriptCore runtime
+        https://bugs.webkit.org/show_bug.cgi?id=114111
+
+        Reviewed by Andreas Kling.
+
+        Almost all the code was already using Vector::reserveInitialCapacity()
+        and Vector::uncheckedAppend(). Fix the remaining parts.
+
+        * runtime/ArgList.h:
+        (MarkedArgumentBuffer): The type VectorType is unused.
+
+        * runtime/ArrayPrototype.cpp:
+        (JSC::arrayProtoFuncSort):
+        Move the variable closer to where it is needed.
+
+        * runtime/JSArray.cpp:
+        (JSC::JSArray::setLengthWithArrayStorage):
+        * runtime/JSObject.cpp:
+        (JSC::JSObject::getOwnPropertyNames):
+
 2013-04-07  Patrick Gansterer  <paroga@webkit.org>
 
         Remove references to Skia and V8 from CMake files
index 1fb1ce9..6b6467c 100644 (file)
@@ -38,7 +38,6 @@ class MarkedArgumentBuffer {
 
 private:
     static const size_t inlineCapacity = 8;
-    typedef Vector<Register, inlineCapacity> VectorType;
     typedef HashSet<MarkedArgumentBuffer*> ListSet;
 
 public:
index e526c19..2152fbc 100644 (file)
@@ -738,8 +738,6 @@ EncodedJSValue JSC_HOST_CALL arrayProtoFuncSort(ExecState* exec)
     if (length < 1000)
         return performSlowSort(exec, thisObj, length, function, callData, callType) ? JSValue::encode(thisObj) : JSValue::encode(jsUndefined());
     
-    Vector<uint32_t> keys;
-    
     JSGlobalObject* globalObject = JSGlobalObject::create(
         exec->globalData(), JSGlobalObject::createStructure(exec->globalData(), jsNull()));
     JSArray* flatArray = constructEmptyArray(globalObject->globalExec(), 0);
@@ -750,7 +748,8 @@ EncodedJSValue JSC_HOST_CALL arrayProtoFuncSort(ExecState* exec)
     thisObj->methodTable()->getPropertyNames(thisObj, exec, nameArray, IncludeDontEnumProperties);
     if (exec->hadException())
         return JSValue::encode(jsUndefined());
-    
+
+    Vector<uint32_t> keys;
     for (size_t i = 0; i < nameArray.size(); ++i) {
         PropertyName name = nameArray[i];
         uint32_t index = name.asIndex();
index cf32e6b..7c717ba 100644 (file)
@@ -350,7 +350,7 @@ bool JSArray::setLengthWithArrayStorage(ExecState* exec, unsigned newLength, boo
         if (newLength < length) {
             // Copy any keys we might be interested in into a vector.
             Vector<unsigned> keys;
-            keys.reserveCapacity(min(map->size(), static_cast<size_t>(length - newLength)));
+            keys.reserveInitialCapacity(min(map->size(), static_cast<size_t>(length - newLength)));
             SparseArrayValueMap::const_iterator end = map->end();
             for (SparseArrayValueMap::const_iterator it = map->begin(); it != end; ++it) {
                 unsigned index = static_cast<unsigned>(it->key);
index d6c1704..d177e32 100644 (file)
@@ -1507,12 +1507,12 @@ void JSObject::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNa
         
         if (SparseArrayValueMap* map = storage->m_sparseMap.get()) {
             Vector<unsigned> keys;
-            keys.reserveCapacity(map->size());
+            keys.reserveInitialCapacity(map->size());
             
             SparseArrayValueMap::const_iterator end = map->end();
             for (SparseArrayValueMap::const_iterator it = map->begin(); it != end; ++it) {
                 if (mode == IncludeDontEnumProperties || !(it->value.attributes & DontEnum))
-                    keys.append(static_cast<unsigned>(it->key));
+                    keys.uncheckedAppend(static_cast<unsigned>(it->key));
             }
             
             std::sort(keys.begin(), keys.end());