| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_ZONE_ZONE_ALLOCATOR_H_ | 5 #ifndef V8_ZONE_ZONE_ALLOCATOR_H_ |
| 6 #define V8_ZONE_ZONE_ALLOCATOR_H_ | 6 #define V8_ZONE_ZONE_ALLOCATOR_H_ |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <new> |
| 8 | 9 |
| 9 #include "src/zone/zone.h" | 10 #include "src/zone/zone.h" |
| 10 | 11 |
| 11 namespace v8 { | 12 namespace v8 { |
| 12 namespace internal { | 13 namespace internal { |
| 13 | 14 |
| 14 template <typename T> | 15 template <typename T> |
| 15 class zone_allocator { | 16 class zone_allocator { |
| 16 public: | 17 public: |
| 17 typedef T* pointer; | 18 typedef T* pointer; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 43 return static_cast<pointer>( | 44 return static_cast<pointer>( |
| 44 zone_->NewArray<value_type>(static_cast<int>(n))); | 45 zone_->NewArray<value_type>(static_cast<int>(n))); |
| 45 } | 46 } |
| 46 void deallocate(pointer p, size_type) { /* noop for Zones */ | 47 void deallocate(pointer p, size_type) { /* noop for Zones */ |
| 47 } | 48 } |
| 48 | 49 |
| 49 size_type max_size() const throw() { | 50 size_type max_size() const throw() { |
| 50 return std::numeric_limits<int>::max() / sizeof(value_type); | 51 return std::numeric_limits<int>::max() / sizeof(value_type); |
| 51 } | 52 } |
| 52 void construct(pointer p, const T& val) { | 53 void construct(pointer p, const T& val) { |
| 53 new (static_cast<void*>(p)) T(val); | 54 ::new (static_cast<void*>(p)) T(val); |
| 54 } | 55 } |
| 55 void destroy(pointer p) { p->~T(); } | 56 void destroy(pointer p) { p->~T(); } |
| 56 | 57 |
| 57 bool operator==(zone_allocator const& other) const { | 58 bool operator==(zone_allocator const& other) const { |
| 58 return zone_ == other.zone_; | 59 return zone_ == other.zone_; |
| 59 } | 60 } |
| 60 bool operator!=(zone_allocator const& other) const { | 61 bool operator!=(zone_allocator const& other) const { |
| 61 return zone_ != other.zone_; | 62 return zone_ != other.zone_; |
| 62 } | 63 } |
| 63 | 64 |
| 64 Zone* zone() { return zone_; } | 65 Zone* zone() { return zone_; } |
| 65 | 66 |
| 66 private: | 67 private: |
| 67 Zone* zone_; | 68 Zone* zone_; |
| 68 }; | 69 }; |
| 69 | 70 |
| 70 typedef zone_allocator<bool> ZoneBoolAllocator; | 71 typedef zone_allocator<bool> ZoneBoolAllocator; |
| 71 typedef zone_allocator<int> ZoneIntAllocator; | 72 typedef zone_allocator<int> ZoneIntAllocator; |
| 72 } // namespace internal | 73 } // namespace internal |
| 73 } // namespace v8 | 74 } // namespace v8 |
| 74 | 75 |
| 75 #endif // V8_ZONE_ZONE_ALLOCATOR_H_ | 76 #endif // V8_ZONE_ZONE_ALLOCATOR_H_ |
| OLD | NEW |