28
28
29
29
namespace jsonifier_internal {
30
30
31
- template <uint64_t multiple> jsonifier_inline uint64_t roundUpToMultiple (uint64_t num) {
31
+ template <uint64_t multiple> JSONIFIER_INLINE uint64_t roundUpToMultiple (uint64_t num) {
32
32
uint64_t remainder = num % multiple;
33
33
return remainder == 0 ? num : num + (multiple - remainder );
34
34
}
35
35
36
- template <int64_t multiple> jsonifier_inline uint64_t roundDownToMultiple (int64_t value) {
36
+ template <int64_t multiple> JSONIFIER_INLINE uint64_t roundDownToMultiple (int64_t value) {
37
37
return static_cast <uint64_t >(value >= 0 ? (value / multiple) * multiple : ((value - multiple + 1 ) / multiple) * multiple);
38
38
}
39
39
40
- template <typename value_type_new> class aligned_allocator : public std ::pmr::polymorphic_allocator<value_type_new> {
40
+ #if defined(_MSC_VER)
41
+
42
+ template <typename value_type> JSONIFIER_INLINE value_type* jsonifierAlignedAlloc (uint64_t size) {
43
+ return static_cast <value_type*>(_aligned_malloc (roundUpToMultiple<BytesPerStep>(size * sizeof (value_type)), BytesPerStep));
44
+ }
45
+
46
+ JSONIFIER_INLINE void jsonifierFree (void * ptr) {
47
+ _aligned_free (ptr);
48
+ }
49
+
50
+ #else
51
+
52
+ template <typename value_type> JSONIFIER_INLINE value_type* jsonifierAlignedAlloc (uint64_t size) {
53
+ return static_cast <value_type*>(std::aligned_alloc (BytesPerStep, roundUpToMultiple<BytesPerStep>(size * sizeof (value_type))));
54
+ }
55
+
56
+ JSONIFIER_INLINE void jsonifierFree (void * ptr) {
57
+ free (ptr);
58
+ }
59
+
60
+ #endif
61
+
62
+ template <typename value_type_new> class aligned_allocator {
41
63
public:
42
64
using value_type = value_type_new;
43
65
using pointer = value_type*;
44
66
using size_type = uint64_t ;
45
- using allocator = std::pmr::polymorphic_allocator<value_type_new>;
46
67
47
- jsonifier_inline pointer allocate (size_type n) {
68
+ JSONIFIER_INLINE pointer allocate (size_type n) {
48
69
if (n == 0 ) {
49
70
return nullptr ;
50
71
}
51
- return static_cast <pointer>( allocator::allocate_bytes (roundUpToMultiple<BytesPerStep>(n * sizeof (value_type)), BytesPerStep) );
72
+ return jsonifierAlignedAlloc<value_type>(n );
52
73
}
53
74
54
- jsonifier_inline void deallocate (pointer ptr, size_type n ) {
75
+ JSONIFIER_INLINE void deallocate (pointer ptr, size_type) {
55
76
if (ptr) {
56
- allocator::deallocate_bytes (ptr, roundUpToMultiple<BytesPerStep>(n * sizeof (value_type)), BytesPerStep );
77
+ jsonifierFree (ptr);
57
78
}
58
79
}
59
80
60
- template <typename ... Args> jsonifier_inline void construct (pointer p, Args &&... args) {
61
- new (p) value_type (std::forward<Args >(args)...);
81
+ template <typename ... arg_types> JSONIFIER_INLINE void construct (pointer p, arg_types &&... args) {
82
+ new (p) value_type (std::forward<arg_types >(args)...);
62
83
}
63
84
64
- jsonifier_inline void destroy (pointer p) {
85
+ JSONIFIER_INLINE void destroy (pointer p) {
65
86
p->~value_type ();
66
87
}
67
88
};
@@ -74,23 +95,23 @@ namespace jsonifier_internal {
74
95
using allocator = aligned_allocator<value_type>;
75
96
using allocator_traits = std::allocator_traits<allocator>;
76
97
77
- jsonifier_inline pointer allocate (size_type count) {
98
+ JSONIFIER_INLINE pointer allocate (size_type count) {
78
99
return allocator_traits::allocate (*this , count);
79
100
}
80
101
81
- jsonifier_inline void deallocate (pointer ptr, size_type count) {
102
+ JSONIFIER_INLINE void deallocate (pointer ptr, size_type count) {
82
103
allocator_traits::deallocate (*this , ptr, count);
83
104
}
84
105
85
- template <typename ... Args> jsonifier_inline void construct (pointer ptr, Args &&... args) {
86
- allocator_traits::construct (*this , ptr, std::forward<Args >(args)...);
106
+ template <typename ... arg_types> JSONIFIER_INLINE void construct (pointer ptr, arg_types &&... args) {
107
+ allocator_traits::construct (*this , ptr, std::forward<arg_types >(args)...);
87
108
}
88
109
89
- jsonifier_inline static size_type maxSize () {
90
- return allocator_traits::max_size (allocator{} );
110
+ JSONIFIER_INLINE size_type maxSize () {
111
+ return allocator_traits::max_size (* this );
91
112
}
92
113
93
- jsonifier_inline void destroy (pointer ptr) {
114
+ JSONIFIER_INLINE void destroy (pointer ptr) {
94
115
allocator_traits::destroy (*this , ptr);
95
116
}
96
117
};
0 commit comments