Commit 05f1cc5d authored by darin@apple.com's avatar darin@apple.com

Make Vector::insert work for move-only types

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

Reviewed by Anders Carlsson.

Source/WebCore:

* history/HistoryItem.cpp:
(WebCore::HistoryItem::padDailyCountsForNewVisit): Call insertVector.
Also added some inline capacity, which should make this faster.

Source/WTF:

* wtf/Vector.h:
(WTF::Vector::insert): Take an rvalue reference instead of a const reference.
(WTF::Vector::insertVector): Renamed to avoid overloading troubles, analogous
to what we did for appendVector.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@157074 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent d18f8811
2013-10-07 Darin Adler <darin@apple.com>
Make Vector::insert work for move-only types
https://bugs.webkit.org/show_bug.cgi?id=122429
Reviewed by Anders Carlsson.
* wtf/Vector.h:
(WTF::Vector::insert): Take an rvalue reference instead of a const reference.
(WTF::Vector::insertVector): Renamed to avoid overloading troubles, analogous
to what we did for appendVector.
2013-10-07 Anders Carlsson <andersca@apple.com>
Fix Windows build.
......
......@@ -644,8 +644,8 @@ public:
template<typename U> bool tryAppend(const U*, size_t);
template<typename U> void insert(size_t position, const U*, size_t);
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 insert(size_t position, U&&);
template<typename U, size_t c> void insertVector(size_t position, const Vector<U, c>&);
void remove(size_t position);
void remove(size_t position, size_t length);
......@@ -1091,22 +1091,24 @@ void Vector<T, inlineCapacity, OverflowHandler>::insert(size_t position, const U
}
template<typename T, size_t inlineCapacity, typename OverflowHandler> template<typename U>
inline void Vector<T, inlineCapacity, OverflowHandler>::insert(size_t position, const U& val)
inline void Vector<T, inlineCapacity, OverflowHandler>::insert(size_t position, U&& value)
{
ASSERT_WITH_SECURITY_IMPLICATION(position <= size());
const U* data = &val;
auto ptr = const_cast<typename std::remove_const<typename std::remove_reference<U>::type>::type*>(std::addressof(value));
if (size() == capacity()) {
data = expandCapacity(size() + 1, data);
ptr = expandCapacity(size() + 1, ptr);
ASSERT(begin());
}
T* spot = begin() + position;
TypeOperations::moveOverlapping(spot, end(), spot + 1);
new (NotNull, spot) T(*data);
new (NotNull, spot) T(std::forward<U>(*ptr));
++m_size;
}
template<typename T, size_t inlineCapacity, typename OverflowHandler> template<typename U, size_t c>
inline void Vector<T, inlineCapacity, OverflowHandler>::insert(size_t position, const Vector<U, c>& val)
inline void Vector<T, inlineCapacity, OverflowHandler>::insertVector(size_t position, const Vector<U, c>& val)
{
insert(position, val.begin(), val.size());
}
......
2013-10-07 Darin Adler <darin@apple.com>
Make Vector::insert work for move-only types
https://bugs.webkit.org/show_bug.cgi?id=122429
Reviewed by Anders Carlsson.
* history/HistoryItem.cpp:
(WebCore::HistoryItem::padDailyCountsForNewVisit): Call insertVector.
Also added some inline capacity, which should make this faster.
2013-10-07 Anders Carlsson <andersca@apple.com>
Update test results.
......@@ -331,11 +331,11 @@ void HistoryItem::padDailyCountsForNewVisit(double time)
int daysElapsed = timeToDay(time) - timeToDay(m_lastVisitedTime);
if (daysElapsed < 0)
daysElapsed = 0;
daysElapsed = 0;
Vector<int> padding;
Vector<int, 32> padding;
padding.fill(0, daysElapsed);
m_dailyVisitCounts.insert(0, padding);
m_dailyVisitCounts.insertVector(0, padding);
}
static const size_t daysPerWeek = 7;
......
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