Remove Vector::prepend
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 May 2013 04:10:14 +0000 (04:10 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 May 2013 04:10:14 +0000 (04:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=115618

Reviewed by Geoffrey Garen.

Source/WebCore:

Replace calls to Vector::prepend with either Vector::insert,
or a combination of Vector::append and Vector::reverse.

* accessibility/AccessibilityObject.cpp:
(WebCore::AccessibilityObject::scrollToGlobalPoint):
* css/CSSGradientValue.cpp:
(WebCore::CSSGradientValue::addStops):
* css/CSSValueList.h:
(WebCore::CSSValueList::prepend):
* dom/Document.cpp:
(WebCore::Document::iconURLs):
* editing/TextIterator.cpp:
(WebCore::SearchBuffer::prependContext):
* editing/VisibleUnits.cpp:
(WebCore::previousBoundary):
(WebCore::nextBoundary):
* history/HistoryItem.cpp:
(WebCore::HistoryItem::padDailyCountsForNewVisit):
(WebCore::HistoryItem::collapseDailyVisitsToWeekly):
* inspector/InjectedScriptHost.cpp:
(WebCore::InjectedScriptHost::addInspectedObject):
* platform/graphics/SVGGlyph.cpp:
(WebCore::charactersWithArabicForm):

Source/WTF:

Given the performance characteristics of prepending something to a Vector, not having prepend
will hopefully make developers think about whether prepending is necessary at all. For example,
the functions in HexNumber.h were easily converted to using Vector::append and then Vector::reverse.

* wtf/HexNumber.h:
(WTF::appendUnsignedAsHex):
(WTF::appendUnsignedAsHexFixedSize):
* wtf/Vector.h:
(Vector):

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

13 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/HexNumber.h
Source/WTF/wtf/Vector.h
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityObject.cpp
Source/WebCore/css/CSSGradientValue.cpp
Source/WebCore/css/CSSValueList.h
Source/WebCore/dom/Document.cpp
Source/WebCore/editing/TextIterator.cpp
Source/WebCore/editing/VisibleUnits.cpp
Source/WebCore/history/HistoryItem.cpp
Source/WebCore/inspector/InjectedScriptHost.cpp
Source/WebCore/platform/graphics/SVGGlyph.cpp

index 69ac709..ea55026 100644 (file)
@@ -1,5 +1,22 @@
 2013-05-05  Anders Carlsson  <andersca@apple.com>
 
+        Remove Vector::prepend
+        https://bugs.webkit.org/show_bug.cgi?id=115618
+
+        Reviewed by Geoffrey Garen.
+
+        Given the performance characteristics of prepending something to a Vector, not having prepend
+        will hopefully make developers think about whether prepending is necessary at all. For example,
+        the functions in HexNumber.h were easily converted to using Vector::append and then Vector::reverse.
+
+        * wtf/HexNumber.h:
+        (WTF::appendUnsignedAsHex):
+        (WTF::appendUnsignedAsHexFixedSize):
+        * wtf/Vector.h:
+        (Vector):
+
+2013-05-05  Anders Carlsson  <andersca@apple.com>
+
         Remove the Vector::append overload that takes a Vector
         https://bugs.webkit.org/show_bug.cgi?id=115535
 
index 9d07ede..b698dd5 100644 (file)
@@ -71,10 +71,11 @@ inline void appendUnsignedAsHex(unsigned number, T& destination, HexConversionMo
     const LChar* hexDigits = Internal::hexDigitsForMode(mode);
     Vector<LChar, 8> result;
     do {
-        result.prepend(hexDigits[number % 16]);
+        result.append(hexDigits[number % 16]);
         number >>= 4;
     } while (number > 0);
 
+    result.reverse();
     destination.append(result.data(), result.size());
 }
 
@@ -87,11 +88,12 @@ inline void appendUnsignedAsHexFixedSize(unsigned number, T& destination, unsign
     const LChar* hexDigits = Internal::hexDigitsForMode(mode);
     Vector<LChar, 8> result;
     do {
-        result.prepend(hexDigits[number % 16]);
+        result.append(hexDigits[number % 16]);
         number >>= 4;
     } while (result.size() < desiredDigits);
 
     ASSERT(result.size() == desiredDigits);
+    result.reverse();
     destination.append(result.data(), result.size());
 }
 
index 7fbcc05..4f3db54 100644 (file)
@@ -627,10 +627,6 @@ namespace WTF {
         template<typename U> void insert(size_t position, const U&);
         template<typename U, size_t c> void insert(size_t position, const Vector<U, c>&);
 
-        template<typename U> void prepend(const U*, size_t);
-        template<typename U> void prepend(const U&);
-        template<typename U, size_t c> void prepend(const Vector<U, c>&);
-
         void remove(size_t position);
         void remove(size_t position, size_t length);
 
@@ -1108,24 +1104,6 @@ namespace WTF {
         insert(position, val.begin(), val.size());
     }
 
-    template<typename T, size_t inlineCapacity, typename OverflowHandler> template<typename U>
-    void Vector<T, inlineCapacity, OverflowHandler>::prepend(const U* data, size_t dataSize)
-    {
-        insert(0, data, dataSize);
-    }
-
-    template<typename T, size_t inlineCapacity, typename OverflowHandler> template<typename U>
-    inline void Vector<T, inlineCapacity, OverflowHandler>::prepend(const U& val)
-    {
-        insert(0, val);
-    }
-   
-    template<typename T, size_t inlineCapacity, typename OverflowHandler> template<typename U, size_t c>
-    inline void Vector<T, inlineCapacity, OverflowHandler>::prepend(const Vector<U, c>& val)
-    {
-        insert(0, val.begin(), val.size());
-    }
-    
     template<typename T, size_t inlineCapacity, typename OverflowHandler>
     inline void Vector<T, inlineCapacity, OverflowHandler>::remove(size_t position)
     {
index d894f36..6af72d4 100644 (file)
@@ -1,3 +1,34 @@
+2013-05-05  Anders Carlsson  <andersca@apple.com>
+
+        Remove Vector::prepend
+        https://bugs.webkit.org/show_bug.cgi?id=115618
+
+        Reviewed by Geoffrey Garen.
+
+        Replace calls to Vector::prepend with either Vector::insert,
+        or a combination of Vector::append and Vector::reverse.
+
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::AccessibilityObject::scrollToGlobalPoint):
+        * css/CSSGradientValue.cpp:
+        (WebCore::CSSGradientValue::addStops):
+        * css/CSSValueList.h:
+        (WebCore::CSSValueList::prepend):
+        * dom/Document.cpp:
+        (WebCore::Document::iconURLs):
+        * editing/TextIterator.cpp:
+        (WebCore::SearchBuffer::prependContext):
+        * editing/VisibleUnits.cpp:
+        (WebCore::previousBoundary):
+        (WebCore::nextBoundary):
+        * history/HistoryItem.cpp:
+        (WebCore::HistoryItem::padDailyCountsForNewVisit):
+        (WebCore::HistoryItem::collapseDailyVisitsToWeekly):
+        * inspector/InjectedScriptHost.cpp:
+        (WebCore::InjectedScriptHost::addInspectedObject):
+        * platform/graphics/SVGGlyph.cpp:
+        (WebCore::charactersWithArabicForm):
+
 2013-05-05  Sam Weinig  <sam@webkit.org>
 
         Remove empty function SQLiteFileSystem::registerSQLiteVFS() and its callers
index 1a3ed8e..e6cf3aa 100644 (file)
@@ -1768,12 +1768,14 @@ void AccessibilityObject::scrollToGlobalPoint(const IntPoint& globalPoint) const
     // Search up the parent chain and create a vector of all scrollable parent objects
     // and ending with this object itself.
     Vector<const AccessibilityObject*> objects;
-    AccessibilityObject* parentObject;
-    for (parentObject = this->parentObject(); parentObject; parentObject = parentObject->parentObject()) {
+
+    objects.append(this);
+    for (AccessibilityObject* parentObject = this->parentObject(); parentObject; parentObject = parentObject->parentObject()) {
         if (parentObject->getScrollableAreaIfScrollable())
-            objects.prepend(parentObject);
+            objects.append(parentObject);
     }
-    objects.append(this);
+
+    objects.reverse();
 
     // Start with the outermost scrollable (the main window) and try to scroll the
     // next innermost object to the given point.
index 3ecabb7..87411e2 100644 (file)
@@ -292,7 +292,7 @@ void CSSGradientValue::addStops(Gradient* gradient, RenderObject* renderer, Rend
                 while (true) {
                     GradientStop newStop = stops[originalFirstStopIndex + srcStopOrdinal];
                     newStop.offset = currOffset;
-                    stops.prepend(newStop);
+                    stops.insert(0, newStop);
                     ++originalFirstStopIndex;
                     if (currOffset < 0)
                         break;
index 1b001e7..d2ca2be 100644 (file)
@@ -54,7 +54,7 @@ public:
     CSSValue* itemWithoutBoundsCheck(size_t index) { return m_values[index].get(); }
 
     void append(PassRefPtr<CSSValue> value) { m_values.append(value); }
-    void prepend(PassRefPtr<CSSValue> value) { m_values.prepend(value); }
+    void prepend(PassRefPtr<CSSValue> value) { m_values.insert(0, value); }
     bool removeAll(CSSValue*);
     bool hasValue(CSSValue*) const;
     PassRefPtr<CSSValueList> copy();
index c23d3e8..dfc4654 100644 (file)
@@ -4540,9 +4540,10 @@ const Vector<IconURL>& Document::iconURLs(int iconTypesMask)
 
         // Put it at the front to ensure that icons seen later take precedence as required by the spec.
         IconURL newURL(linkElement->href(), linkElement->iconSizes(), linkElement->type(), linkElement->iconType());
-        m_iconURLs.prepend(newURL);
+        m_iconURLs.append(newURL);
     }
 
+    m_iconURLs.reverse();
     return m_iconURLs;
 }
 
index b815222..ba72034 100644 (file)
@@ -2035,7 +2035,7 @@ inline void SearchBuffer::prependContext(const UChar* characters, size_t length)
     }
 
     size_t usableLength = min(m_buffer.capacity() - m_prefixLength, length - wordBoundaryContextStart);
-    m_buffer.prepend(characters + length - usableLength, usableLength);
+    m_buffer.insert(0, characters + length - usableLength, usableLength);
     m_prefixLength += usableLength;
 
     if (wordBoundaryContextStart || m_prefixLength == m_buffer.capacity())
index c27cf45..5ea8203 100644 (file)
@@ -491,12 +491,12 @@ static VisiblePosition previousBoundary(const VisiblePosition& c, BoundarySearch
     while (!it.atEnd()) {
         // iterate to get chunks until the searchFunction returns a non-zero value.
         if (!inTextSecurityMode) 
-            string.prepend(it.characters(), it.length());
+            string.insert(0, it.characters(), it.length());
         else {
             // Treat bullets used in the text security mode as regular characters when looking for boundaries
             String iteratorString(it.characters(), it.length());
             iteratorString.fill('x');
-            string.prepend(iteratorString.characters(), iteratorString.length());
+            string.insert(0, iteratorString.characters(), iteratorString.length());
         }
         next = searchFunction(string.data(), string.size(), string.size() - suffixLength, MayHaveMoreContext, needMoreContext);
         if (next > 1) // FIXME: This is a work around for https://webkit.org/b/115070. We need to provide more contexts in general case.
@@ -547,7 +547,7 @@ static VisiblePosition nextBoundary(const VisiblePosition& c, BoundarySearchFunc
             const UChar* characters = backwardsIterator.characters();
             int length = backwardsIterator.length();
             int i = startOfLastWordBoundaryContext(characters, length);
-            string.prepend(characters + i, length - i);
+            string.insert(0, characters + i, length - i);
             prefixLength += length - i;
             if (i > 0)
                 break;
index 6b5a658..1608c8f 100644 (file)
@@ -327,7 +327,7 @@ static inline int timeToDay(double time)
 void HistoryItem::padDailyCountsForNewVisit(double time)
 {
     if (m_dailyVisitCounts.isEmpty())
-        m_dailyVisitCounts.prepend(m_visitCount);
+        m_dailyVisitCounts.insert(0, m_visitCount);
 
     int daysElapsed = timeToDay(time) - timeToDay(m_lastVisitedTime);
 
@@ -336,7 +336,7 @@ void HistoryItem::padDailyCountsForNewVisit(double time)
 
     Vector<int> padding;
     padding.fill(0, daysElapsed);
-    m_dailyVisitCounts.prepend(padding);
+    m_dailyVisitCounts.insert(0, padding);
 }
 
 static const size_t daysPerWeek = 7;
@@ -350,7 +350,7 @@ void HistoryItem::collapseDailyVisitsToWeekly()
         for (size_t i = 0; i < daysPerWeek; i++)
             oldestWeekTotal += m_dailyVisitCounts[m_dailyVisitCounts.size() - daysPerWeek + i];
         m_dailyVisitCounts.shrink(m_dailyVisitCounts.size() - daysPerWeek);
-        m_weeklyVisitCounts.prepend(oldestWeekTotal);
+        m_weeklyVisitCounts.insert(0, oldestWeekTotal);
     }
 
     if (m_weeklyVisitCounts.size() > maxWeeklyCounts)
index 2e634d4..a8eb403 100644 (file)
@@ -130,7 +130,7 @@ ScriptValue InjectedScriptHost::InspectableObject::get(ScriptState*)
 
 void InjectedScriptHost::addInspectedObject(PassOwnPtr<InjectedScriptHost::InspectableObject> object)
 {
-    m_inspectedObjects.prepend(object);
+    m_inspectedObjects.insert(0, object);
     while (m_inspectedObjects.size() > 5)
         m_inspectedObjects.removeLast();
 }
index 6681344..e2820e4 100644 (file)
@@ -101,7 +101,7 @@ Vector<SVGGlyph::ArabicForm> charactersWithArabicForm(const String& input, bool
     // Start identifying arabic forms
     if (rtl) {
         for (int i = length - 1; i >= 0; --i)
-            forms.prepend(processArabicFormDetection(input[i], lastCharShapesRight, forms.isEmpty() ? 0 : &forms.first()));
+            forms.insert(0, processArabicFormDetection(input[i], lastCharShapesRight, forms.isEmpty() ? 0 : &forms.first()));
     } else {
         for (unsigned i = 0; i < length; ++i)
             forms.append(processArabicFormDetection(input[i], lastCharShapesRight, forms.isEmpty() ? 0 : &forms.last()));