| 157 | } |
| 158 | |
| 159 | Bytes Bytes::slice(unsigned start, unsigned len) const |
| 160 | { |
| 161 | start += _low; |
| 162 | unsigned end = start + len; |
| 163 | if (start >= _high) |
| 164 | { |
| 165 | /* Asking for a completely out-of-range slice --- just return zeroes. */ |
| 166 | return Bytes(len); |
| 167 | } |
| 168 | else if (end > _high) |
| 169 | { |
| 170 | /* Can't share the buffer, as we need to zero-pad the end. */ |
| 171 | Bytes b(len); |
| 172 | std::uninitialized_copy( |
| 173 | _data->cbegin() + start, _data->cbegin() + _high, b._data->begin()); |
| 174 | return b; |
| 175 | } |
| 176 | else |
| 177 | { |
| 178 | /* Use the magic of shared_ptr to share the data. */ |
| 179 | Bytes b(_data, start, end); |
| 180 | return b; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | Bytes Bytes::slice(unsigned start) const |
| 185 | { |