| OLD | NEW |
| 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 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 #include "wtf/Alignment.h" | 24 #include "wtf/Alignment.h" |
| 25 #include "wtf/ConditionalDestructor.h" | 25 #include "wtf/ConditionalDestructor.h" |
| 26 #include "wtf/ContainerAnnotations.h" | 26 #include "wtf/ContainerAnnotations.h" |
| 27 #include "wtf/Noncopyable.h" | 27 #include "wtf/Noncopyable.h" |
| 28 #include "wtf/NotFound.h" | 28 #include "wtf/NotFound.h" |
| 29 #include "wtf/StdLibExtras.h" | 29 #include "wtf/StdLibExtras.h" |
| 30 #include "wtf/VectorTraits.h" | 30 #include "wtf/VectorTraits.h" |
| 31 #include "wtf/allocator/PartitionAllocator.h" | 31 #include "wtf/allocator/PartitionAllocator.h" |
| 32 #include <algorithm> | 32 #include <algorithm> |
| 33 #include <initializer_list> |
| 33 #include <iterator> | 34 #include <iterator> |
| 34 #include <string.h> | 35 #include <string.h> |
| 35 #include <utility> | 36 #include <utility> |
| 36 | 37 |
| 37 // For ASAN builds, disable inline buffers completely as they cause various issu
es. | 38 // For ASAN builds, disable inline buffers completely as they cause various issu
es. |
| 38 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER | 39 #ifdef ANNOTATE_CONTIGUOUS_CONTAINER |
| 39 #define INLINE_CAPACITY 0 | 40 #define INLINE_CAPACITY 0 |
| 40 #else | 41 #else |
| 41 #define INLINE_CAPACITY inlineCapacity | 42 #define INLINE_CAPACITY inlineCapacity |
| 42 #endif | 43 #endif |
| (...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 template <size_t otherCapacity> | 825 template <size_t otherCapacity> |
| 825 explicit Vector(const Vector<T, otherCapacity, Allocator>&); | 826 explicit Vector(const Vector<T, otherCapacity, Allocator>&); |
| 826 | 827 |
| 827 Vector& operator=(const Vector&); | 828 Vector& operator=(const Vector&); |
| 828 template <size_t otherCapacity> | 829 template <size_t otherCapacity> |
| 829 Vector& operator=(const Vector<T, otherCapacity, Allocator>&); | 830 Vector& operator=(const Vector<T, otherCapacity, Allocator>&); |
| 830 | 831 |
| 831 Vector(Vector&&); | 832 Vector(Vector&&); |
| 832 Vector& operator=(Vector&&); | 833 Vector& operator=(Vector&&); |
| 833 | 834 |
| 835 Vector(std::initializer_list<T> elements); |
| 836 Vector& operator=(std::initializer_list<T> elements); |
| 837 |
| 834 size_t size() const { return m_size; } | 838 size_t size() const { return m_size; } |
| 835 size_t capacity() const { return Base::capacity(); } | 839 size_t capacity() const { return Base::capacity(); } |
| 836 bool isEmpty() const { return !size(); } | 840 bool isEmpty() const { return !size(); } |
| 837 | 841 |
| 838 T& at(size_t i) | 842 T& at(size_t i) |
| 839 { | 843 { |
| 840 RELEASE_ASSERT(i < size()); | 844 RELEASE_ASSERT(i < size()); |
| 841 return Base::buffer()[i]; | 845 return Base::buffer()[i]; |
| 842 } | 846 } |
| 843 const T& at(size_t i) const | 847 const T& at(size_t i) const |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 } | 1047 } |
| 1044 | 1048 |
| 1045 template <typename T, size_t inlineCapacity, typename Allocator> | 1049 template <typename T, size_t inlineCapacity, typename Allocator> |
| 1046 Vector<T, inlineCapacity, Allocator>& Vector<T, inlineCapacity, Allocator>::oper
ator=(Vector<T, inlineCapacity, Allocator>&& other) | 1050 Vector<T, inlineCapacity, Allocator>& Vector<T, inlineCapacity, Allocator>::oper
ator=(Vector<T, inlineCapacity, Allocator>&& other) |
| 1047 { | 1051 { |
| 1048 swap(other); | 1052 swap(other); |
| 1049 return *this; | 1053 return *this; |
| 1050 } | 1054 } |
| 1051 | 1055 |
| 1052 template <typename T, size_t inlineCapacity, typename Allocator> | 1056 template <typename T, size_t inlineCapacity, typename Allocator> |
| 1057 Vector<T, inlineCapacity, Allocator>::Vector(std::initializer_list<T> elements) |
| 1058 : Base(elements.size()) |
| 1059 { |
| 1060 ANNOTATE_NEW_BUFFER(begin(), capacity(), elements.size()); |
| 1061 m_size = elements.size(); |
| 1062 TypeOperations::uninitializedCopy(elements.begin(), elements.end(), begin())
; |
| 1063 } |
| 1064 |
| 1065 template <typename T, size_t inlineCapacity, typename Allocator> |
| 1066 Vector<T, inlineCapacity, Allocator>& Vector<T, inlineCapacity, Allocator>::oper
ator=(std::initializer_list<T> elements) |
| 1067 { |
| 1068 if (size() > elements.size()) { |
| 1069 shrink(elements.size()); |
| 1070 } else if (elements.size() > capacity()) { |
| 1071 clear(); |
| 1072 reserveCapacity(elements.size()); |
| 1073 DCHECK(begin()); |
| 1074 } |
| 1075 |
| 1076 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, elements.size()); |
| 1077 std::copy(elements.begin(), elements.begin() + m_size, begin()); |
| 1078 TypeOperations::uninitializedCopy(elements.begin() + m_size, elements.end(),
end()); |
| 1079 m_size = elements.size(); |
| 1080 |
| 1081 return *this; |
| 1082 } |
| 1083 |
| 1084 template <typename T, size_t inlineCapacity, typename Allocator> |
| 1053 template <typename U> | 1085 template <typename U> |
| 1054 bool Vector<T, inlineCapacity, Allocator>::contains(const U& value) const | 1086 bool Vector<T, inlineCapacity, Allocator>::contains(const U& value) const |
| 1055 { | 1087 { |
| 1056 return find(value) != kNotFound; | 1088 return find(value) != kNotFound; |
| 1057 } | 1089 } |
| 1058 | 1090 |
| 1059 template <typename T, size_t inlineCapacity, typename Allocator> | 1091 template <typename T, size_t inlineCapacity, typename Allocator> |
| 1060 template <typename U> | 1092 template <typename U> |
| 1061 size_t Vector<T, inlineCapacity, Allocator>::find(const U& value) const | 1093 size_t Vector<T, inlineCapacity, Allocator>::find(const U& value) const |
| 1062 { | 1094 { |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1496 Allocator::template trace<VisitorDispatcher, T, VectorTraits<T>>(vis
itor, *const_cast<T*>(bufferEntry)); | 1528 Allocator::template trace<VisitorDispatcher, T, VectorTraits<T>>(vis
itor, *const_cast<T*>(bufferEntry)); |
| 1497 checkUnusedSlots(buffer() + size(), buffer() + capacity()); | 1529 checkUnusedSlots(buffer() + size(), buffer() + capacity()); |
| 1498 } | 1530 } |
| 1499 } | 1531 } |
| 1500 | 1532 |
| 1501 } // namespace WTF | 1533 } // namespace WTF |
| 1502 | 1534 |
| 1503 using WTF::Vector; | 1535 using WTF::Vector; |
| 1504 | 1536 |
| 1505 #endif // WTF_Vector_h | 1537 #endif // WTF_Vector_h |
| OLD | NEW |