/// <summary> /// Append this slice's data, by copying it into this stream's private buffers. /// </summary> public override void Append(Slice <TTime, TValue> source) { HoloDebug.Assert(!IsShut); // Try to keep copying source into _remainingFreeBuffer while (!source.IsEmpty()) { EnsureFreeBuffer(); // if source is larger than available free buffer, then we'll iterate Slice <TTime, TValue> originalSource = source; if (source.Duration > _remainingFreeBuffer.Duration) { source = source.Subslice(0, _remainingFreeBuffer.Duration); } // now we know source can fit Slice <TTime, TValue> dest = _remainingFreeBuffer.SubsliceOfDuration(source.Duration); source.CopyTo(dest); // dest may well be adjacent to the previous slice, if there is one, since we may // be appending onto an open chunk. So here is where we coalesce this, if so. dest = InternalAppend(dest); // and update our loop variables source = originalSource.SubsliceStartingAt(source.Duration); Trim(); } }
void EnsureFreeBuffer() { if (_remainingFreeBuffer.IsEmpty()) { Buf <TValue> chunk = _allocator.Allocate(); _remainingFreeBuffer = new Slice <TTime, TValue>( chunk, 0, (chunk.Data.Length / SliverSize), SliverSize); } }