MCPcopy Create free account
hub / github.com/dengwirda/jigsaw / reallocate

Method reallocate

src/libcpp/allocators/alloc_item.hpp:133–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131 */
132
133 __inline_call data_type* reallocate (
134 data_type*_addr,
135 size_type _old_alloc ,
136 size_type _new_alloc ,
137 size_type _old_count
138 )
139 {
140 /*------------------------- allocate a new raw buffer */
141 data_type *_rptr =
142 (data_type *)allocator:: allocate (
143 _new_alloc * sizeof(data_type)) ;
144
145 /*------- copy objects to new buffer, free old buffer */
146 if (_addr != nullptr)
147 {
148 __write_ptr(data_type) _head = _addr ;
149 __write_ptr(data_type) _tail ;
150 __write_ptr(data_type) _item = _rptr ;
151
152 /*--- number of ctor'd items to be moved to _rptr */
153 size_type _new_count = std::min (
154 _old_count, _new_alloc);
155
156 /*-------------------- move items between buffers */
157 _tail = _addr + _new_count;
158 for ( ; _head != _tail; ++_head,
159 ++_item)
160 {
161 /*--------- move ctor'd items from _addr to _rptr */
162 construct(_item, std::move(*_head)) ;
163 _destruct(_head) ;
164 }
165 _tail = _addr + _old_count;
166 for ( ; _head != _tail; ++_head)
167 {
168 /*-------- _destruct all remaining items in _addr */
169 _destruct(_head) ;
170 }
171
172 allocator:: deallocate((char_type*)_addr,
173 _old_alloc * sizeof(data_type)) ;
174 }
175
176 return ( _rptr ) ;
177 }
178
179 /*
180 --------------------------------------------------------

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected