| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "platform/wtf/Assertions.h" | |
| 32 #include "platform/wtf/ContainerAnnotations.h" | |
| 33 #include "platform/wtf/PassRefPtr.h" | |
| 34 #include "platform/wtf/RefCounted.h" | |
| 35 #include "platform/wtf/RefPtr.h" | |
| 36 #include "platform/wtf/ThreadRestrictionVerifier.h" | |
| 37 #include "platform/wtf/Vector.h" | |
| 38 #include "platform/wtf/text/AtomicString.h" | |
| 39 #include "platform/wtf/text/WTFString.h" | |
| 40 #include <memory> | |
| 41 | |
| 42 namespace WTF { | |
| 43 | |
| 44 #if DCHECK_IS_ON() || ENABLE(SECURITY_ASSERT) | |
| 45 // The debug/assertion version may get bigger. | |
| 46 struct SameSizeAsRefCounted { | |
| 47 int a; | |
| 48 #if ENABLE(SECURITY_ASSERT) | |
| 49 bool b; | |
| 50 #endif | |
| 51 #if DCHECK_IS_ON() | |
| 52 bool c; | |
| 53 ThreadRestrictionVerifier d; | |
| 54 #endif | |
| 55 }; | |
| 56 #else | |
| 57 struct SameSizeAsRefCounted { | |
| 58 int a; | |
| 59 // Don't add anything here because this should stay small. | |
| 60 }; | |
| 61 #endif | |
| 62 template <typename T, unsigned inlineCapacity = 0> | |
| 63 struct SameSizeAsVectorWithInlineCapacity; | |
| 64 | |
| 65 template <typename T> | |
| 66 struct SameSizeAsVectorWithInlineCapacity<T, 0> { | |
| 67 void* bufferPointer; | |
| 68 unsigned capacity; | |
| 69 unsigned size; | |
| 70 }; | |
| 71 | |
| 72 template <typename T, unsigned inlineCapacity> | |
| 73 struct SameSizeAsVectorWithInlineCapacity { | |
| 74 SameSizeAsVectorWithInlineCapacity<T, 0> baseCapacity; | |
| 75 #if !defined(ANNOTATE_CONTIGUOUS_CONTAINER) | |
| 76 AlignedBuffer<inlineCapacity * sizeof(T), WTF_ALIGN_OF(T)> inlineBuffer; | |
| 77 #endif | |
| 78 }; | |
| 79 | |
| 80 static_assert(sizeof(std::unique_ptr<int>) == sizeof(int*), | |
| 81 "std::unique_ptr should stay small"); | |
| 82 static_assert(sizeof(PassRefPtr<RefCounted<int>>) == sizeof(int*), | |
| 83 "PassRefPtr should stay small"); | |
| 84 static_assert(sizeof(RefCounted<int>) == sizeof(SameSizeAsRefCounted), | |
| 85 "RefCounted should stay small"); | |
| 86 static_assert(sizeof(RefPtr<RefCounted<int>>) == sizeof(int*), | |
| 87 "RefPtr should stay small"); | |
| 88 static_assert(sizeof(String) == sizeof(int*), "String should stay small"); | |
| 89 static_assert(sizeof(AtomicString) == sizeof(String), | |
| 90 "AtomicString should stay small"); | |
| 91 static_assert(sizeof(Vector<int>) == | |
| 92 sizeof(SameSizeAsVectorWithInlineCapacity<int>), | |
| 93 "Vector should stay small"); | |
| 94 static_assert(sizeof(Vector<int, 1>) == | |
| 95 sizeof(SameSizeAsVectorWithInlineCapacity<int, 1>), | |
| 96 "Vector should stay small"); | |
| 97 static_assert(sizeof(Vector<int, 2>) == | |
| 98 sizeof(SameSizeAsVectorWithInlineCapacity<int, 2>), | |
| 99 "Vector should stay small"); | |
| 100 static_assert(sizeof(Vector<int, 3>) == | |
| 101 sizeof(SameSizeAsVectorWithInlineCapacity<int, 3>), | |
| 102 "Vector should stay small"); | |
| 103 } // namespace WTF | |
| OLD | NEW |