| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrAllocator_DEFINED | 8 #ifndef GrAllocator_DEFINED |
| 9 #define GrAllocator_DEFINED | 9 #define GrAllocator_DEFINED |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 /** | 42 /** |
| 43 * Adds an item and returns pointer to it. | 43 * Adds an item and returns pointer to it. |
| 44 * | 44 * |
| 45 * @return pointer to the added item. | 45 * @return pointer to the added item. |
| 46 */ | 46 */ |
| 47 void* push_back() { | 47 void* push_back() { |
| 48 int indexInBlock = fCount % fItemsPerBlock; | 48 int indexInBlock = fCount % fItemsPerBlock; |
| 49 // we always have at least one block | 49 // we always have at least one block |
| 50 if (0 == indexInBlock) { | 50 if (0 == indexInBlock) { |
| 51 if (0 != fCount) { | 51 if (0 != fCount) { |
| 52 fBlocks.push_back() = GrMalloc(fBlockSize); | 52 fBlocks.push_back() = sk_malloc_throw(fBlockSize); |
| 53 } else if (fOwnFirstBlock) { | 53 } else if (fOwnFirstBlock) { |
| 54 fBlocks[0] = GrMalloc(fBlockSize); | 54 fBlocks[0] = sk_malloc_throw(fBlockSize); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 void* ret = (char*)fBlocks[fCount/fItemsPerBlock] + | 57 void* ret = (char*)fBlocks[fCount/fItemsPerBlock] + |
| 58 fItemSize * indexInBlock; | 58 fItemSize * indexInBlock; |
| 59 ++fCount; | 59 ++fCount; |
| 60 return ret; | 60 return ret; |
| 61 } | 61 } |
| 62 | 62 |
| 63 /** | 63 /** |
| 64 * removes all added items | 64 * removes all added items |
| 65 */ | 65 */ |
| 66 void reset() { | 66 void reset() { |
| 67 int blockCount = GrMax((unsigned)1, | 67 int blockCount = GrMax((unsigned)1, |
| 68 GrUIDivRoundUp(fCount, fItemsPerBlock)); | 68 GrUIDivRoundUp(fCount, fItemsPerBlock)); |
| 69 for (int i = 1; i < blockCount; ++i) { | 69 for (int i = 1; i < blockCount; ++i) { |
| 70 GrFree(fBlocks[i]); | 70 sk_free(fBlocks[i]); |
| 71 } | 71 } |
| 72 if (fOwnFirstBlock) { | 72 if (fOwnFirstBlock) { |
| 73 GrFree(fBlocks[0]); | 73 sk_free(fBlocks[0]); |
| 74 fBlocks[0] = NULL; | 74 fBlocks[0] = NULL; |
| 75 } | 75 } |
| 76 fBlocks.pop_back_n(blockCount-1); | 76 fBlocks.pop_back_n(blockCount-1); |
| 77 fCount = 0; | 77 fCount = 0; |
| 78 } | 78 } |
| 79 | 79 |
| 80 /** | 80 /** |
| 81 * count of items | 81 * count of items |
| 82 */ | 82 */ |
| 83 int count() const { | 83 int count() const { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 238 |
| 239 public: | 239 public: |
| 240 GrSTAllocator() : INHERITED(N, fStorage.get()) { | 240 GrSTAllocator() : INHERITED(N, fStorage.get()) { |
| 241 } | 241 } |
| 242 | 242 |
| 243 private: | 243 private: |
| 244 SkAlignedSTStorage<N, T> fStorage; | 244 SkAlignedSTStorage<N, T> fStorage; |
| 245 }; | 245 }; |
| 246 | 246 |
| 247 #endif | 247 #endif |
| OLD | NEW |