diff options
author | Yi Kong | 2018-07-16 20:11:34 -0500 |
---|---|---|
committer | Yi Kong | 2018-07-16 20:11:34 -0500 |
commit | e1731a4f2e05f1abb4a45602067708851eaf1e14 (patch) | |
tree | 339c0ce3d3de7d6f5e0fb9bdada9b6210d1d470f /libutils/VectorImpl.cpp | |
parent | 895acebe946e34d2626716c5c4d7d7f2cc28c39d (diff) | |
download | platform-system-core-e1731a4f2e05f1abb4a45602067708851eaf1e14.tar.gz platform-system-core-e1731a4f2e05f1abb4a45602067708851eaf1e14.tar.xz platform-system-core-e1731a4f2e05f1abb4a45602067708851eaf1e14.zip |
[libutils] Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.
Test: m
Bug: 68236239
Change-Id: I5e89ec8c42151875439d2656475a8739ab9cb7dc
Diffstat (limited to 'libutils/VectorImpl.cpp')
-rw-r--r-- | libutils/VectorImpl.cpp | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/libutils/VectorImpl.cpp b/libutils/VectorImpl.cpp index ef3277f42..00a904d93 100644 --- a/libutils/VectorImpl.cpp +++ b/libutils/VectorImpl.cpp | |||
@@ -44,7 +44,7 @@ static inline size_t max(size_t a, size_t b) { | |||
44 | // ---------------------------------------------------------------------------- | 44 | // ---------------------------------------------------------------------------- |
45 | 45 | ||
46 | VectorImpl::VectorImpl(size_t itemSize, uint32_t flags) | 46 | VectorImpl::VectorImpl(size_t itemSize, uint32_t flags) |
47 | : mStorage(0), mCount(0), mFlags(flags), mItemSize(itemSize) | 47 | : mStorage(nullptr), mCount(0), mFlags(flags), mItemSize(itemSize) |
48 | { | 48 | { |
49 | } | 49 | } |
50 | 50 | ||
@@ -77,7 +77,7 @@ VectorImpl& VectorImpl::operator = (const VectorImpl& rhs) | |||
77 | mCount = rhs.mCount; | 77 | mCount = rhs.mCount; |
78 | SharedBuffer::bufferFromData(mStorage)->acquire(); | 78 | SharedBuffer::bufferFromData(mStorage)->acquire(); |
79 | } else { | 79 | } else { |
80 | mStorage = 0; | 80 | mStorage = nullptr; |
81 | mCount = 0; | 81 | mCount = 0; |
82 | } | 82 | } |
83 | } | 83 | } |
@@ -89,14 +89,14 @@ void* VectorImpl::editArrayImpl() | |||
89 | if (mStorage) { | 89 | if (mStorage) { |
90 | const SharedBuffer* sb = SharedBuffer::bufferFromData(mStorage); | 90 | const SharedBuffer* sb = SharedBuffer::bufferFromData(mStorage); |
91 | SharedBuffer* editable = sb->attemptEdit(); | 91 | SharedBuffer* editable = sb->attemptEdit(); |
92 | if (editable == 0) { | 92 | if (editable == nullptr) { |
93 | // If we're here, we're not the only owner of the buffer. | 93 | // If we're here, we're not the only owner of the buffer. |
94 | // We must make a copy of it. | 94 | // We must make a copy of it. |
95 | editable = SharedBuffer::alloc(sb->size()); | 95 | editable = SharedBuffer::alloc(sb->size()); |
96 | // Fail instead of returning a pointer to storage that's not | 96 | // Fail instead of returning a pointer to storage that's not |
97 | // editable. Otherwise we'd be editing the contents of a buffer | 97 | // editable. Otherwise we'd be editing the contents of a buffer |
98 | // for which we're not the only owner, which is undefined behaviour. | 98 | // for which we're not the only owner, which is undefined behaviour. |
99 | LOG_ALWAYS_FATAL_IF(editable == NULL); | 99 | LOG_ALWAYS_FATAL_IF(editable == nullptr); |
100 | _do_copy(editable->data(), mStorage, mCount); | 100 | _do_copy(editable->data(), mStorage, mCount); |
101 | release_storage(); | 101 | release_storage(); |
102 | mStorage = editable->data(); | 102 | mStorage = editable->data(); |
@@ -141,7 +141,7 @@ ssize_t VectorImpl::appendArray(const void* array, size_t length) | |||
141 | 141 | ||
142 | ssize_t VectorImpl::insertAt(size_t index, size_t numItems) | 142 | ssize_t VectorImpl::insertAt(size_t index, size_t numItems) |
143 | { | 143 | { |
144 | return insertAt(0, index, numItems); | 144 | return insertAt(nullptr, index, numItems); |
145 | } | 145 | } |
146 | 146 | ||
147 | ssize_t VectorImpl::insertAt(const void* item, size_t index, size_t numItems) | 147 | ssize_t VectorImpl::insertAt(const void* item, size_t index, size_t numItems) |
@@ -177,7 +177,7 @@ status_t VectorImpl::sort(VectorImpl::compar_r_t cmp, void* state) | |||
177 | const ssize_t count = size(); | 177 | const ssize_t count = size(); |
178 | if (count > 1) { | 178 | if (count > 1) { |
179 | void* array = const_cast<void*>(arrayImpl()); | 179 | void* array = const_cast<void*>(arrayImpl()); |
180 | void* temp = 0; | 180 | void* temp = nullptr; |
181 | ssize_t i = 1; | 181 | ssize_t i = 1; |
182 | while (i < count) { | 182 | while (i < count) { |
183 | void* item = reinterpret_cast<char*>(array) + mItemSize*(i); | 183 | void* item = reinterpret_cast<char*>(array) + mItemSize*(i); |
@@ -205,7 +205,7 @@ status_t VectorImpl::sort(VectorImpl::compar_r_t cmp, void* state) | |||
205 | _do_copy(next, curr, 1); | 205 | _do_copy(next, curr, 1); |
206 | next = curr; | 206 | next = curr; |
207 | --j; | 207 | --j; |
208 | curr = NULL; | 208 | curr = nullptr; |
209 | if (j >= 0) { | 209 | if (j >= 0) { |
210 | curr = reinterpret_cast<char*>(array) + mItemSize*(j); | 210 | curr = reinterpret_cast<char*>(array) + mItemSize*(j); |
211 | } | 211 | } |
@@ -233,7 +233,7 @@ void VectorImpl::pop() | |||
233 | 233 | ||
234 | void VectorImpl::push() | 234 | void VectorImpl::push() |
235 | { | 235 | { |
236 | push(0); | 236 | push(nullptr); |
237 | } | 237 | } |
238 | 238 | ||
239 | void VectorImpl::push(const void* item) | 239 | void VectorImpl::push(const void* item) |
@@ -243,7 +243,7 @@ void VectorImpl::push(const void* item) | |||
243 | 243 | ||
244 | ssize_t VectorImpl::add() | 244 | ssize_t VectorImpl::add() |
245 | { | 245 | { |
246 | return add(0); | 246 | return add(nullptr); |
247 | } | 247 | } |
248 | 248 | ||
249 | ssize_t VectorImpl::add(const void* item) | 249 | ssize_t VectorImpl::add(const void* item) |
@@ -253,7 +253,7 @@ ssize_t VectorImpl::add(const void* item) | |||
253 | 253 | ||
254 | ssize_t VectorImpl::replaceAt(size_t index) | 254 | ssize_t VectorImpl::replaceAt(size_t index) |
255 | { | 255 | { |
256 | return replaceAt(0, index); | 256 | return replaceAt(nullptr, index); |
257 | } | 257 | } |
258 | 258 | ||
259 | ssize_t VectorImpl::replaceAt(const void* prototype, size_t index) | 259 | ssize_t VectorImpl::replaceAt(const void* prototype, size_t index) |
@@ -267,10 +267,10 @@ ssize_t VectorImpl::replaceAt(const void* prototype, size_t index) | |||
267 | 267 | ||
268 | void* item = editItemLocation(index); | 268 | void* item = editItemLocation(index); |
269 | if (item != prototype) { | 269 | if (item != prototype) { |
270 | if (item == 0) | 270 | if (item == nullptr) |
271 | return NO_MEMORY; | 271 | return NO_MEMORY; |
272 | _do_destroy(item, 1); | 272 | _do_destroy(item, 1); |
273 | if (prototype == 0) { | 273 | if (prototype == nullptr) { |
274 | _do_construct(item, 1); | 274 | _do_construct(item, 1); |
275 | } else { | 275 | } else { |
276 | _do_copy(item, prototype, 1); | 276 | _do_copy(item, prototype, 1); |
@@ -294,7 +294,7 @@ ssize_t VectorImpl::removeItemsAt(size_t index, size_t count) | |||
294 | void VectorImpl::finish_vector() | 294 | void VectorImpl::finish_vector() |
295 | { | 295 | { |
296 | release_storage(); | 296 | release_storage(); |
297 | mStorage = 0; | 297 | mStorage = nullptr; |
298 | mCount = 0; | 298 | mCount = 0; |
299 | } | 299 | } |
300 | 300 | ||
@@ -315,7 +315,7 @@ void* VectorImpl::editItemLocation(size_t index) | |||
315 | return reinterpret_cast<char*>(buffer) + index*mItemSize; | 315 | return reinterpret_cast<char*>(buffer) + index*mItemSize; |
316 | } | 316 | } |
317 | } | 317 | } |
318 | return 0; | 318 | return nullptr; |
319 | } | 319 | } |
320 | 320 | ||
321 | const void* VectorImpl::itemLocation(size_t index) const | 321 | const void* VectorImpl::itemLocation(size_t index) const |
@@ -330,7 +330,7 @@ const void* VectorImpl::itemLocation(size_t index) const | |||
330 | return reinterpret_cast<const char*>(buffer) + index*mItemSize; | 330 | return reinterpret_cast<const char*>(buffer) + index*mItemSize; |
331 | } | 331 | } |
332 | } | 332 | } |
333 | return 0; | 333 | return nullptr; |
334 | } | 334 | } |
335 | 335 | ||
336 | ssize_t VectorImpl::setCapacity(size_t new_capacity) | 336 | ssize_t VectorImpl::setCapacity(size_t new_capacity) |
@@ -418,7 +418,7 @@ void* VectorImpl::_grow(size_t where, size_t amount) | |||
418 | if (sb) { | 418 | if (sb) { |
419 | mStorage = sb->data(); | 419 | mStorage = sb->data(); |
420 | } else { | 420 | } else { |
421 | return NULL; | 421 | return nullptr; |
422 | } | 422 | } |
423 | } else { | 423 | } else { |
424 | SharedBuffer* sb = SharedBuffer::alloc(new_alloc_size); | 424 | SharedBuffer* sb = SharedBuffer::alloc(new_alloc_size); |
@@ -435,7 +435,7 @@ void* VectorImpl::_grow(size_t where, size_t amount) | |||
435 | release_storage(); | 435 | release_storage(); |
436 | mStorage = const_cast<void*>(array); | 436 | mStorage = const_cast<void*>(array); |
437 | } else { | 437 | } else { |
438 | return NULL; | 438 | return nullptr; |
439 | } | 439 | } |
440 | } | 440 | } |
441 | } else { | 441 | } else { |