Replace the Refs[Dst :] by Slice[Src : Src + Length)
| 107 | |
| 108 | /// Replace the Refs[Dst :] by Slice[Src : Src + Length) |
| 109 | Expect<void> setRefs(Span<const RefVariant> Slice, const uint64_t Dst, |
| 110 | const uint64_t Src, const uint64_t Length) noexcept { |
| 111 | // Check the accessing boundary. |
| 112 | if (!checkAccessBound(Dst, Length)) { |
| 113 | spdlog::error(ErrCode::Value::TableOutOfBounds); |
| 114 | spdlog::error(ErrInfo::InfoBoundary(Dst, Length, getSize())); |
| 115 | return Unexpect(ErrCode::Value::TableOutOfBounds); |
| 116 | } |
| 117 | |
| 118 | // Check the input data validation. |
| 119 | if (std::numeric_limits<uint64_t>::max() - Src < Length || |
| 120 | Src + Length > Slice.size()) { |
| 121 | spdlog::error(ErrCode::Value::TableOutOfBounds); |
| 122 | spdlog::error(ErrInfo::InfoBoundary(Src, Length, Slice.size())); |
| 123 | return Unexpect(ErrCode::Value::TableOutOfBounds); |
| 124 | } |
| 125 | |
| 126 | // Copy the references. |
| 127 | if (Dst <= Src) { |
| 128 | std::copy(Slice.begin() + Src, Slice.begin() + Src + Length, |
| 129 | Refs.begin() + static_cast<std::ptrdiff_t>(Dst)); |
| 130 | } else { |
| 131 | std::copy(std::make_reverse_iterator(Slice.begin() + Src + Length), |
| 132 | std::make_reverse_iterator(Slice.begin() + Src), |
| 133 | std::make_reverse_iterator( |
| 134 | Refs.begin() + static_cast<std::ptrdiff_t>(Dst + Length))); |
| 135 | } |
| 136 | return {}; |
| 137 | } |
| 138 | |
| 139 | /// Fill the Refs[Offset : Offset + Length - 1] by Val. |
| 140 | Expect<void> fillRefs(const RefVariant &Val, const uint64_t Offset, |