| 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 24 matching lines...) Expand all Loading... |
| 35 #include "wtf/RefCounted.h" | 35 #include "wtf/RefCounted.h" |
| 36 #include "wtf/Vector.h" | 36 #include "wtf/Vector.h" |
| 37 | 37 |
| 38 namespace WebCore { | 38 namespace WebCore { |
| 39 | 39 |
| 40 // An arena which allocates only Plain Old Data (POD), or classes and | 40 // An arena which allocates only Plain Old Data (POD), or classes and |
| 41 // structs bottoming out in Plain Old Data. NOTE: the constructors of | 41 // structs bottoming out in Plain Old Data. NOTE: the constructors of |
| 42 // the objects allocated in this arena are called, but _not_ their | 42 // the objects allocated in this arena are called, but _not_ their |
| 43 // destructors. | 43 // destructors. |
| 44 | 44 |
| 45 class PODArena : public RefCounted<PODArena> { | 45 class PODArena FINAL : public RefCounted<PODArena> { |
| 46 public: | 46 public: |
| 47 // The arena is configured with an allocator, which is responsible | 47 // The arena is configured with an allocator, which is responsible |
| 48 // for allocating and freeing chunks of memory at a time. | 48 // for allocating and freeing chunks of memory at a time. |
| 49 class Allocator : public RefCounted<Allocator> { | 49 class Allocator : public RefCounted<Allocator> { |
| 50 public: | 50 public: |
| 51 virtual void* allocate(size_t size) = 0; | 51 virtual void* allocate(size_t size) = 0; |
| 52 virtual void free(void* ptr) = 0; | 52 virtual void free(void* ptr) = 0; |
| 53 protected: | 53 protected: |
| 54 virtual ~Allocator() { } | 54 virtual ~Allocator() { } |
| 55 friend class WTF::RefCounted<Allocator>; | 55 friend class WTF::RefCounted<Allocator>; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } | 139 } |
| 140 | 140 |
| 141 // Rounds up the given allocation size to the specified alignment. | 141 // Rounds up the given allocation size to the specified alignment. |
| 142 size_t roundUp(size_t size, size_t alignment) | 142 size_t roundUp(size_t size, size_t alignment) |
| 143 { | 143 { |
| 144 ASSERT(!(alignment % 2)); | 144 ASSERT(!(alignment % 2)); |
| 145 return (size + alignment - 1) & ~(alignment - 1); | 145 return (size + alignment - 1) & ~(alignment - 1); |
| 146 } | 146 } |
| 147 | 147 |
| 148 // Manages a chunk of memory and individual allocations out of it. | 148 // Manages a chunk of memory and individual allocations out of it. |
| 149 class Chunk { | 149 class Chunk FINAL { |
| 150 WTF_MAKE_NONCOPYABLE(Chunk); | 150 WTF_MAKE_NONCOPYABLE(Chunk); |
| 151 public: | 151 public: |
| 152 // Allocates a block of memory of the given size from the passed | 152 // Allocates a block of memory of the given size from the passed |
| 153 // Allocator. | 153 // Allocator. |
| 154 Chunk(Allocator* allocator, size_t size) | 154 Chunk(Allocator* allocator, size_t size) |
| 155 : m_allocator(allocator) | 155 : m_allocator(allocator) |
| 156 , m_size(size) | 156 , m_size(size) |
| 157 , m_currentOffset(0) | 157 , m_currentOffset(0) |
| 158 { | 158 { |
| 159 m_base = static_cast<uint8_t*>(m_allocator->allocate(size)); | 159 m_base = static_cast<uint8_t*>(m_allocator->allocate(size)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 191 |
| 192 RefPtr<Allocator> m_allocator; | 192 RefPtr<Allocator> m_allocator; |
| 193 Chunk* m_current; | 193 Chunk* m_current; |
| 194 size_t m_currentChunkSize; | 194 size_t m_currentChunkSize; |
| 195 Vector<OwnPtr<Chunk> > m_chunks; | 195 Vector<OwnPtr<Chunk> > m_chunks; |
| 196 }; | 196 }; |
| 197 | 197 |
| 198 } // namespace WebCore | 198 } // namespace WebCore |
| 199 | 199 |
| 200 #endif // PODArena_h | 200 #endif // PODArena_h |
| OLD | NEW |