Showing the changes to src/vm/array.cpp (1 of 6 files). Show all
Unified · Split
| @@ -43,16 +43,14 @@ vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t lengt · 42 unmodified lines | ||
| 43 | 43 | debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "end: init: elements: %d", array_len); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | −vm_array_t::vm_array_t(vm_array_t *original, word_t begin_index, word_t length) | |
| 46 | +vm_array_t::vm_array_t(vm_array_t &original, word_t begin_index, word_t length) | |
| 47 | 47 | : vm_alloc_t(vm_array_t::type_desc()) |
| 48 | 48 | , _arr{ nullptr } |
| 49 | − , _element_type{ original->get_element_type() } | |
| 49 | + , _element_type{ original.get_element_type() } | |
| 50 | 50 | , _length{ length } |
| 51 | − , _original{ original } | |
| 51 | + , _original{ &original } | |
| 52 | 52 | { |
| 53 | − assert(_original != nullptr); | |
| 54 | − assert(0 <= begin_index && begin_index < _original->get_length()); | |
| 55 | − assert(_length >= 0 && (_length + begin_index) <= _original->get_length()); | |
| 53 | + assert(0 <= begin_index && (begin_index < _original->get_length() || (begin_index == _original->get_length() && length == 0))); | |
| 56 | 54 | |
| 57 | 55 | if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>()) |
| 58 | 56 | debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm array: slice: %d %d", begin_index, _length); |
| @@ -164,7 +162,6 @@ void vm_array_t::copy_from(const vm_array_t &source, word_t this_begin_index) · 105 unmodified lines | ||
| 164 | 162 | { |
| 165 | 163 | // [PERF] There is a chance this copy is within the same array, therefore |
| 166 | 164 | // a check could be made to not ref count memory that is going to be moved. |
| 167 | − // The Inferno implementation of slicela handles this case (libinterp/xec.c). | |
| 168 | 165 | const auto &type_desc = *_element_type; |
| 169 | 166 | auto source_array_element = source._arr; |
| 170 | 167 | auto dest_array_element = dest_arr; |
| @@ -173,7 +170,7 @@ void vm_array_t::copy_from(const vm_array_t &source, word_t this_begin_index) · 2 unmodified lines | ||
| 173 | 170 | inc_ref_count_in_memory(type_desc, source_array_element); |
| 174 | 171 | source_array_element += type_desc.size_in_bytes; |
| 175 | 172 | |
| 176 | − destroy_memory(type_desc, dest_array_element); | |
| 173 | + dec_ref_count_in_memory(type_desc, dest_array_element); | |
| 177 | 174 | dest_array_element += type_desc.size_in_bytes; |
| 178 | 175 | } |
| 179 | 176 | } |