| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 #include "wtf/ArrayBufferContents.h" | 28 #include "wtf/ArrayBufferContents.h" |
| 29 | 29 |
| 30 #include "wtf/ArrayBufferDeallocationObserver.h" | 30 #include "wtf/ArrayBufferDeallocationObserver.h" |
| 31 #include <string.h> |
| 31 | 32 |
| 32 namespace WTF { | 33 namespace WTF { |
| 33 | 34 |
| 34 ArrayBufferContents::ArrayBufferContents() | 35 ArrayBufferContents::ArrayBufferContents() |
| 35 : m_data(0) | 36 : m_data(0) |
| 36 , m_sizeInBytes(0) | 37 , m_sizeInBytes(0) |
| 37 , m_deallocationObserver(0) { } | 38 , m_deallocationObserver(0) { } |
| 38 | 39 |
| 39 ArrayBufferContents::ArrayBufferContents(unsigned numElements, unsigned elementB
yteSize, ArrayBufferContents::InitializationPolicy policy) | 40 ArrayBufferContents::ArrayBufferContents(unsigned numElements, unsigned elementB
yteSize, ArrayBufferContents::InitializationPolicy policy) |
| 40 : m_data(0) | 41 : m_data(0) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 91 } |
| 91 | 92 |
| 92 void ArrayBufferContents::transfer(ArrayBufferContents& other) | 93 void ArrayBufferContents::transfer(ArrayBufferContents& other) |
| 93 { | 94 { |
| 94 ASSERT(!other.m_data); | 95 ASSERT(!other.m_data); |
| 95 other.m_data = m_data; | 96 other.m_data = m_data; |
| 96 other.m_sizeInBytes = m_sizeInBytes; | 97 other.m_sizeInBytes = m_sizeInBytes; |
| 97 clear(); | 98 clear(); |
| 98 } | 99 } |
| 99 | 100 |
| 101 void ArrayBufferContents::copyTo(ArrayBufferContents& other) |
| 102 { |
| 103 ASSERT(!other.m_sizeInBytes); |
| 104 other.freeMemory(other.m_data); |
| 105 allocateMemory(m_sizeInBytes, DontInitialize, other.m_data); |
| 106 if (!other.m_data) |
| 107 return; |
| 108 memcpy(other.m_data, m_data, m_sizeInBytes); |
| 109 other.m_sizeInBytes = m_sizeInBytes; |
| 110 } |
| 111 |
| 100 bool ArrayBufferContents::allocateMemory(size_t size, InitializationPolicy polic
y, void*& data) | 112 bool ArrayBufferContents::allocateMemory(size_t size, InitializationPolicy polic
y, void*& data) |
| 101 { | 113 { |
| 102 if (policy == ZeroInitialize) { | 114 if (policy == ZeroInitialize) { |
| 103 return WTF::tryFastCalloc(size, 1).getValue(data); | 115 return WTF::tryFastCalloc(size, 1).getValue(data); |
| 104 } | 116 } |
| 105 ASSERT(policy == DontInitialize); | 117 ASSERT(policy == DontInitialize); |
| 106 return WTF::tryFastMalloc(size).getValue(data); | 118 return WTF::tryFastMalloc(size).getValue(data); |
| 107 } | 119 } |
| 108 | 120 |
| 109 void ArrayBufferContents::freeMemory(void * data) | 121 void ArrayBufferContents::freeMemory(void * data) |
| 110 { | 122 { |
| 111 WTF::fastFree(data); | 123 WTF::fastFree(data); |
| 112 } | 124 } |
| 113 | 125 |
| 114 } // namespace WTF | 126 } // namespace WTF |
| OLD | NEW |