Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Unified Diff: third_party/WebKit/Source/wtf/Vector.h

Issue 2365533003: Add WTF::Vector::emplaceAppend() (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/VectorTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/Vector.h
diff --git a/third_party/WebKit/Source/wtf/Vector.h b/third_party/WebKit/Source/wtf/Vector.h
index 5b50284b29f3c98f244e66884144907583cd4659..5d98d9b8fa829218f512880c3c860137d5418a80 100644
--- a/third_party/WebKit/Source/wtf/Vector.h
+++ b/third_party/WebKit/Source/wtf/Vector.h
@@ -917,6 +917,7 @@ public:
template <typename U> void append(const U*, size_t);
template <typename U> void append(U&&);
+ template <typename... Args> void emplaceAppend(Args&&...);
template <typename U> void uncheckedAppend(U&& val);
template <typename U, size_t otherCapacity, typename V> void appendVector(const Vector<U, otherCapacity, V>&);
@@ -1367,6 +1368,23 @@ ALWAYS_INLINE void Vector<T, inlineCapacity, Allocator>::append(U&& val)
appendSlowCase(std::forward<U>(val));
}
+
+template <typename T, size_t inlineCapacity, typename Allocator>
+template <typename... Args>
+ALWAYS_INLINE void Vector<T, inlineCapacity, Allocator>::emplaceAppend(Args&&... args)
+{
+ static_assert(sizeof...(Args), "grow() must be called instead");
+ static_assert(sizeof...(Args) != 1, "append() must be called instead");
+
+ DCHECK(Allocator::isAllocationAllowed());
+ if (UNLIKELY(size() == capacity()))
+ expandCapacity(size() + 1);
+
+ ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, m_size + 1);
+ new (NotNull, end()) T(std::forward<Args>(args)...);
+ ++m_size;
+}
+
template <typename T, size_t inlineCapacity, typename Allocator>
template <typename U>
NEVER_INLINE void Vector<T, inlineCapacity, Allocator>::appendSlowCase(U&& val)
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/VectorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698