| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SkPtrRecorder.h" | 8 #include "SkPtrRecorder.h" |
| 9 #include "SkTSearch.h" | 9 #include "SkTSearch.h" |
| 10 | 10 |
| 11 void SkPtrSet::reset() { | 11 void SkPtrSet::reset() { |
| 12 Pair* p = fList.begin(); | 12 Pair* p = fList.begin(); |
| 13 Pair* stop = fList.end(); | 13 Pair* stop = fList.end(); |
| 14 while (p < stop) { | 14 while (p < stop) { |
| 15 this->decPtr(p->fPtr); | 15 this->decPtr(p->fPtr); |
| 16 p += 1; | 16 p += 1; |
| 17 } | 17 } |
| 18 fList.reset(); | 18 fList.reset(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 bool SkPtrSet::Less(const Pair& a, const Pair& b) { | 21 bool SkPtrSet::Less(const Pair& a, const Pair& b) { |
| 22 return (char*)a.fPtr < (char*)b.fPtr; | 22 return (char*)a.fPtr < (char*)b.fPtr; |
| 23 } | 23 } |
| 24 | 24 |
| 25 uint32_t SkPtrSet::find(void* ptr) const { | 25 uint32_t SkPtrSet::find(void* ptr) const { |
| 26 if (NULL == ptr) { | 26 if (nullptr == ptr) { |
| 27 return 0; | 27 return 0; |
| 28 } | 28 } |
| 29 | 29 |
| 30 int count = fList.count(); | 30 int count = fList.count(); |
| 31 Pair pair; | 31 Pair pair; |
| 32 pair.fPtr = ptr; | 32 pair.fPtr = ptr; |
| 33 | 33 |
| 34 int index = SkTSearch<Pair, Less>(fList.begin(), count, pair, sizeof(pair)); | 34 int index = SkTSearch<Pair, Less>(fList.begin(), count, pair, sizeof(pair)); |
| 35 if (index < 0) { | 35 if (index < 0) { |
| 36 return 0; | 36 return 0; |
| 37 } | 37 } |
| 38 return fList[index].fIndex; | 38 return fList[index].fIndex; |
| 39 } | 39 } |
| 40 | 40 |
| 41 uint32_t SkPtrSet::add(void* ptr) { | 41 uint32_t SkPtrSet::add(void* ptr) { |
| 42 if (NULL == ptr) { | 42 if (nullptr == ptr) { |
| 43 return 0; | 43 return 0; |
| 44 } | 44 } |
| 45 | 45 |
| 46 int count = fList.count(); | 46 int count = fList.count(); |
| 47 Pair pair; | 47 Pair pair; |
| 48 pair.fPtr = ptr; | 48 pair.fPtr = ptr; |
| 49 | 49 |
| 50 int index = SkTSearch<Pair, Less>(fList.begin(), count, pair, sizeof(pair)); | 50 int index = SkTSearch<Pair, Less>(fList.begin(), count, pair, sizeof(pair)); |
| 51 if (index < 0) { | 51 if (index < 0) { |
| 52 index = ~index; // turn it back into an index for insertion | 52 index = ~index; // turn it back into an index for insertion |
| (...skipping 12 matching lines...) Expand all Loading... |
| 65 SkASSERT(array); | 65 SkASSERT(array); |
| 66 const Pair* p = fList.begin(); | 66 const Pair* p = fList.begin(); |
| 67 // p->fIndex is base-1, so we need to subtract to find its slot | 67 // p->fIndex is base-1, so we need to subtract to find its slot |
| 68 for (int i = 0; i < count; i++) { | 68 for (int i = 0; i < count; i++) { |
| 69 int index = p[i].fIndex - 1; | 69 int index = p[i].fIndex - 1; |
| 70 SkASSERT((unsigned)index < (unsigned)count); | 70 SkASSERT((unsigned)index < (unsigned)count); |
| 71 array[index] = p[i].fPtr; | 71 array[index] = p[i].fPtr; |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 } | 74 } |
| OLD | NEW |