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

Side by Side Diff: Source/wtf/ArrayBufferContents.cpp

Issue 1532413002: Added Dartium changes onto 45.0.2454.104 (Closed) Base URL: http://src.chromium.org/blink/branches/chromium/2454
Patch Set: Created 5 years 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
OLDNEW
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 m_holder->allocateNew(totalSize, isShared, policy); 53 m_holder->allocateNew(totalSize, isShared, policy);
54 } 54 }
55 55
56 ArrayBufferContents::ArrayBufferContents( 56 ArrayBufferContents::ArrayBufferContents(
57 void* data, unsigned sizeInBytes, SharingType isShared) 57 void* data, unsigned sizeInBytes, SharingType isShared)
58 : m_holder(adoptRef(new DataHolder())) 58 : m_holder(adoptRef(new DataHolder()))
59 { 59 {
60 if (data) { 60 if (data) {
61 m_holder->adopt(data, sizeInBytes, isShared); 61 m_holder->adopt(data, sizeInBytes, isShared);
62 m_holder->setAllocated(false);
62 } else { 63 } else {
63 ASSERT(!sizeInBytes); 64 ASSERT(!sizeInBytes);
64 sizeInBytes = 0; 65 sizeInBytes = 0;
65 // Allow null data if size is 0 bytes, make sure data is valid pointer. 66 // Allow null data if size is 0 bytes, make sure data is valid pointer.
66 // (PartitionAlloc guarantees valid pointer for size 0) 67 // (PartitionAlloc guarantees valid pointer for size 0)
67 m_holder->allocateNew(sizeInBytes, isShared, ZeroInitialize); 68 m_holder->allocateNew(sizeInBytes, isShared, ZeroInitialize);
68 } 69 }
69 } 70 }
70 71
71 ArrayBufferContents::~ArrayBufferContents() 72 ArrayBufferContents::~ArrayBufferContents()
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 110
110 void ArrayBufferContents::freeMemory(void* data, size_t size) 111 void ArrayBufferContents::freeMemory(void* data, size_t size)
111 { 112 {
112 partitionFreeGeneric(WTF::Partitions::bufferPartition(), data); 113 partitionFreeGeneric(WTF::Partitions::bufferPartition(), data);
113 if (s_adjustAmountOfExternalAllocatedMemoryFunction) 114 if (s_adjustAmountOfExternalAllocatedMemoryFunction)
114 s_adjustAmountOfExternalAllocatedMemoryFunction(-static_cast<int>(size)) ; 115 s_adjustAmountOfExternalAllocatedMemoryFunction(-static_cast<int>(size)) ;
115 } 116 }
116 117
117 ArrayBufferContents::DataHolder::DataHolder() 118 ArrayBufferContents::DataHolder::DataHolder()
118 : m_data(nullptr) 119 : m_data(nullptr)
120 , m_malloc(false)
119 , m_sizeInBytes(0) 121 , m_sizeInBytes(0)
120 , m_isShared(NotShared) { } 122 , m_isShared(NotShared) { }
121 123
122 ArrayBufferContents::DataHolder::~DataHolder() 124 ArrayBufferContents::DataHolder::~DataHolder()
123 { 125 {
124 ArrayBufferContents::freeMemory(m_data, m_sizeInBytes); 126 if (m_malloc)
127 ArrayBufferContents::freeMemory(m_data, m_sizeInBytes);
125 128
126 m_data = nullptr; 129 m_data = nullptr;
127 m_sizeInBytes = 0; 130 m_sizeInBytes = 0;
128 m_isShared = NotShared; 131 m_isShared = NotShared;
132 m_malloc = false;
129 } 133 }
130 134
131 void ArrayBufferContents::DataHolder::allocateNew(unsigned sizeInBytes, SharingT ype isShared, InitializationPolicy policy) 135 void ArrayBufferContents::DataHolder::allocateNew(unsigned sizeInBytes, SharingT ype isShared, InitializationPolicy policy)
132 { 136 {
133 ASSERT(!m_data); 137 ASSERT(!m_data);
134 void* data = nullptr; 138 void* data = nullptr;
135 allocateMemory(sizeInBytes, policy, data); 139 allocateMemory(sizeInBytes, policy, data);
136 m_data = data; 140 m_data = data;
137 m_sizeInBytes = data ? sizeInBytes : 0; 141 m_sizeInBytes = data ? sizeInBytes : 0;
138 m_isShared = isShared; 142 m_isShared = isShared;
143 m_malloc = true;
139 } 144 }
140 145
141 void ArrayBufferContents::DataHolder::adopt(void* data, unsigned sizeInBytes, Sh aringType isShared) 146 void ArrayBufferContents::DataHolder::adopt(void* data, unsigned sizeInBytes, Sh aringType isShared)
142 { 147 {
143 ASSERT(!m_data); 148 ASSERT(!m_data);
144 m_data = data; 149 m_data = data;
145 m_sizeInBytes = sizeInBytes; 150 m_sizeInBytes = sizeInBytes;
146 m_isShared = isShared; 151 m_isShared = isShared;
147 } 152 }
148 153
149 void ArrayBufferContents::DataHolder::copyMemoryTo(DataHolder& other) 154 void ArrayBufferContents::DataHolder::copyMemoryTo(DataHolder& other)
150 { 155 {
151 ASSERT(!other.m_sizeInBytes); 156 ASSERT(!other.m_sizeInBytes);
152 ArrayBufferContents::freeMemory(other.m_data, other.m_sizeInBytes); 157 ArrayBufferContents::freeMemory(other.m_data, other.m_sizeInBytes);
153 ArrayBufferContents::allocateMemory(m_sizeInBytes, DontInitialize, other.m_d ata); 158 ArrayBufferContents::allocateMemory(m_sizeInBytes, DontInitialize, other.m_d ata);
154 if (!other.m_data) 159 if (!other.m_data)
155 return; 160 return;
156 memcpy(other.m_data, m_data, m_sizeInBytes); 161 memcpy(other.m_data, m_data, m_sizeInBytes);
157 other.m_sizeInBytes = m_sizeInBytes; 162 other.m_sizeInBytes = m_sizeInBytes;
158 } 163 }
159 164
160 } // namespace WTF 165 } // namespace WTF
OLDNEW
« no previous file with comments | « Source/wtf/ArrayBufferContents.h ('k') | Tools/Scripts/webkitpy/layout_tests/controllers/single_test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698