| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 void* ptr = 0; | 124 void* ptr = 0; |
| 125 size_t roundedSize = roundUp(sizeof(T), minAlignment<T>()); | 125 size_t roundedSize = roundUp(sizeof(T), minAlignment<T>()); |
| 126 if (m_current) | 126 if (m_current) |
| 127 ptr = m_current->allocate(roundedSize); | 127 ptr = m_current->allocate(roundedSize); |
| 128 | 128 |
| 129 if (!ptr) { | 129 if (!ptr) { |
| 130 if (roundedSize > m_currentChunkSize) | 130 if (roundedSize > m_currentChunkSize) |
| 131 m_currentChunkSize = roundedSize; | 131 m_currentChunkSize = roundedSize; |
| 132 m_chunks.append( | 132 m_chunks.append( |
| 133 wrapUnique(new Chunk(m_allocator.get(), m_currentChunkSize))); | 133 wrapUnique(new Chunk(m_allocator.get(), m_currentChunkSize))); |
| 134 m_current = m_chunks.last().get(); | 134 m_current = m_chunks.back().get(); |
| 135 ptr = m_current->allocate(roundedSize); | 135 ptr = m_current->allocate(roundedSize); |
| 136 } | 136 } |
| 137 return ptr; | 137 return ptr; |
| 138 } | 138 } |
| 139 | 139 |
| 140 // Rounds up the given allocation size to the specified alignment. | 140 // Rounds up the given allocation size to the specified alignment. |
| 141 size_t roundUp(size_t size, size_t alignment) { | 141 size_t roundUp(size_t size, size_t alignment) { |
| 142 ASSERT(!(alignment % 2)); | 142 ASSERT(!(alignment % 2)); |
| 143 return (size + alignment - 1) & ~(alignment - 1); | 143 return (size + alignment - 1) & ~(alignment - 1); |
| 144 } | 144 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 184 |
| 185 RefPtr<Allocator> m_allocator; | 185 RefPtr<Allocator> m_allocator; |
| 186 Chunk* m_current; | 186 Chunk* m_current; |
| 187 size_t m_currentChunkSize; | 187 size_t m_currentChunkSize; |
| 188 Vector<std::unique_ptr<Chunk>> m_chunks; | 188 Vector<std::unique_ptr<Chunk>> m_chunks; |
| 189 }; | 189 }; |
| 190 | 190 |
| 191 } // namespace blink | 191 } // namespace blink |
| 192 | 192 |
| 193 #endif // PODArena_h | 193 #endif // PODArena_h |
| OLD | NEW |