| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 SkFreeList_DEFINED | 8 #ifndef SkFreeList_DEFINED |
| 9 #define SkFreeList_DEFINED | 9 #define SkFreeList_DEFINED |
| 10 | 10 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 * Returns the number of items immediately available without having to | 67 * Returns the number of items immediately available without having to |
| 68 * construct any new ones. | 68 * construct any new ones. |
| 69 */ | 69 */ |
| 70 int available() const { return fAvailable.getCount(); } | 70 int available() const { return fAvailable.getCount(); } |
| 71 | 71 |
| 72 /** | 72 /** |
| 73 * Returns the number of blocks of items the pool has allocated so far. | 73 * Returns the number of blocks of items the pool has allocated so far. |
| 74 */ | 74 */ |
| 75 int blocks() const { return fBlocks.getCount(); } | 75 int blocks() const { return fBlocks.getCount(); } |
| 76 | 76 |
| 77 /** |
| 78 * Returns the number of items allocated by the pool in total. |
| 79 */ |
| 80 int allocated() const { return fBlocks.getCount() * numItemsPerBlock; } |
| 81 |
| 77 private: | 82 private: |
| 78 /** | 83 /** |
| 79 * The type for a new block of entries for the list. | 84 * The type for a new block of entries for the list. |
| 80 */ | 85 */ |
| 81 struct Block { | 86 struct Block { |
| 82 T entries[numItemsPerBlock]; | 87 T entries[numItemsPerBlock]; |
| 83 SK_DECLARE_INTERNAL_SLIST_INTERFACE(Block); | 88 SK_DECLARE_INTERNAL_SLIST_INTERFACE(Block); |
| 84 }; | 89 }; |
| 85 SkTInternalSList<Block> fBlocks; | 90 SkTInternalSList<Block> fBlocks; |
| 86 SkTInternalSList<T> fAvailable; | 91 SkTInternalSList<T> fAvailable; |
| 87 | 92 |
| 88 /** | 93 /** |
| 89 * When the free list runs out of items, this method is called to allocate | 94 * When the free list runs out of items, this method is called to allocate |
| 90 * a new block of them. | 95 * a new block of them. |
| 91 * It calls the constructors and then pushes the nodes into the available | 96 * It calls the constructors and then pushes the nodes into the available |
| 92 * list. | 97 * list. |
| 93 */ | 98 */ |
| 94 void grow() { | 99 void grow() { |
| 95 Block* block = SkNEW(Block); | 100 Block* block = SkNEW(Block); |
| 96 fBlocks.push(block); | 101 fBlocks.push(block); |
| 97 for(int index = 0; index < numItemsPerBlock; ++index) { | 102 for(int index = 0; index < numItemsPerBlock; ++index) { |
| 98 fAvailable.push(&block->entries[index]); | 103 fAvailable.push(&block->entries[index]); |
| 99 } | 104 } |
| 100 } | 105 } |
| 101 | 106 |
| 102 }; | 107 }; |
| 103 | 108 |
| 104 #endif | 109 #endif |
| OLD | NEW |