Return a segment of a ByteVector that shares the same memory as the original.
| 118 | |
| 119 | // Return a segment of a ByteVector that shares the same memory as the original. |
| 120 | ByteVector ByteVector::segment(size_t start, size_t span) const |
| 121 | { |
| 122 | #if NEW_SEGMENT_SEMANTICS |
| 123 | BVASSERT(start+span <= size()); |
| 124 | ByteVector result(*this); |
| 125 | result.mStart = mStart + start; |
| 126 | result.mSizeBits = span*8; |
| 127 | //result.mEnd = result.mStart + span; |
| 128 | //BVASSERT(result.mEnd<=mEnd); |
| 129 | return result; |
| 130 | #else |
| 131 | ByteType* wStart = mStart + start; |
| 132 | ByteType* wEnd = wStart + span; |
| 133 | BVASSERT(wEnd<=mEnd); |
| 134 | return ByteVector(wStart,wEnd); |
| 135 | #endif |
| 136 | } |
| 137 | |
| 138 | // This returns a segment that does not share ownership of the original memory, |
| 139 | // so when the original is deleted, this is destroyed also, and without warning. |