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

Side by Side Diff: third_party/WebKit/Source/wtf/Vector.h

Issue 2739813003: Allow WTF::Vector::emplace_back accept one or zero arguments (Closed)
Patch Set: Added emplace_back() overload Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/VectorTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 // iterators (for appendRange) to the back. The elements will be copied. 1106 // iterators (for appendRange) to the back. The elements will be copied.
1107 // uncheckedAppend(value) 1107 // uncheckedAppend(value)
1108 // Insert a single element like push_back(), but this function assumes 1108 // Insert a single element like push_back(), but this function assumes
1109 // the vector has enough capacity such that it can store the new element 1109 // the vector has enough capacity such that it can store the new element
1110 // without a reallocation. Using this function could improve the 1110 // without a reallocation. Using this function could improve the
1111 // performance when you append many elements repeatedly. 1111 // performance when you append many elements repeatedly.
1112 template <typename U> 1112 template <typename U>
1113 void push_back(U&&); 1113 void push_back(U&&);
1114 template <typename... Args> 1114 template <typename... Args>
1115 T& emplace_back(Args&&...); 1115 T& emplace_back(Args&&...);
1116 ALWAYS_INLINE T& emplace_back() {
1117 grow(m_size + 1);
1118 return back();
1119 }
1116 template <typename U> 1120 template <typename U>
1117 void append(const U*, size_t); 1121 void append(const U*, size_t);
1118 template <typename U, size_t otherCapacity, typename V> 1122 template <typename U, size_t otherCapacity, typename V>
1119 void appendVector(const Vector<U, otherCapacity, V>&); 1123 void appendVector(const Vector<U, otherCapacity, V>&);
1120 template <typename Iterator> 1124 template <typename Iterator>
1121 void appendRange(Iterator begin, Iterator end); 1125 void appendRange(Iterator begin, Iterator end);
1122 template <typename U> 1126 template <typename U>
1123 void uncheckedAppend(U&&); 1127 void uncheckedAppend(U&&);
1124 1128
1125 // Insertion to an arbitrary position. All of these functions will take 1129 // Insertion to an arbitrary position. All of these functions will take
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1660 return; 1664 return;
1661 } 1665 }
1662 1666
1663 appendSlowCase(std::forward<U>(val)); 1667 appendSlowCase(std::forward<U>(val));
1664 } 1668 }
1665 1669
1666 template <typename T, size_t inlineCapacity, typename Allocator> 1670 template <typename T, size_t inlineCapacity, typename Allocator>
1667 template <typename... Args> 1671 template <typename... Args>
1668 ALWAYS_INLINE T& Vector<T, inlineCapacity, Allocator>::emplace_back( 1672 ALWAYS_INLINE T& Vector<T, inlineCapacity, Allocator>::emplace_back(
1669 Args&&... args) { 1673 Args&&... args) {
1670 static_assert(sizeof...(Args), "grow() must be called instead");
1671 static_assert(sizeof...(Args) != 1, "append() must be called instead");
1672
1673 DCHECK(Allocator::isAllocationAllowed()); 1674 DCHECK(Allocator::isAllocationAllowed());
1674 if (UNLIKELY(size() == capacity())) 1675 if (UNLIKELY(size() == capacity()))
1675 expandCapacity(size() + 1); 1676 expandCapacity(size() + 1);
1676 1677
1677 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, m_size + 1); 1678 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, m_size + 1);
1678 T* t = new (NotNull, end()) T(std::forward<Args>(args)...); 1679 T* t = new (NotNull, end()) T(std::forward<Args>(args)...);
1679 ++m_size; 1680 ++m_size;
1680 return *t; 1681 return *t;
1681 } 1682 }
1682 1683
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1900 visitor, *const_cast<T*>(bufferEntry)); 1901 visitor, *const_cast<T*>(bufferEntry));
1901 checkUnusedSlots(buffer() + size(), buffer() + capacity()); 1902 checkUnusedSlots(buffer() + size(), buffer() + capacity());
1902 } 1903 }
1903 } 1904 }
1904 1905
1905 } // namespace WTF 1906 } // namespace WTF
1906 1907
1907 using WTF::Vector; 1908 using WTF::Vector;
1908 1909
1909 #endif // WTF_Vector_h 1910 #endif // WTF_Vector_h
OLDNEW
« 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