private unsafe void ReadLinesImpl(IAddResult result, int max_lines) { int line_count = 0; line_count += this.PickLinesImpl(result, max_lines); if (line_count == max_lines) { return; } _lines.Clear(); while (line_count < max_lines) { if (_blockPos < _blockNum && _worker.IsEmpty) { this.ReadStream(); fixed(byte *byte_ptr = _byteBuffer) { var handle = new GCHandle <Decoder>(); handle.Create(_decoder); _worker.DecodeTextIntoBuffer(byte_ptr, _byteLength, handle); handle.Dispose(); _worker.GetLines(_lines); } } line_count += this.PickLinesImpl(result, max_lines - line_count); if (line_count == max_lines) { return; } if (_blockPos == _blockNum) { // if final part do not have LF. if (!_worker.IsEmpty) { var buff = new NativeList <Char16>(Allocator.Temp); _worker.GetInternalBuffer(buff); result.AddResult((char *)buff.GetUnsafePtr(), buff.Length); buff.Dispose(); } // reach EOF break; } } }
private unsafe int PickLinesImpl(IAddResult result, int max_lines) { int line_count = 0; if (_lines.Length > 0) { int n_lines = Math.Min(_lines.Length, max_lines); for (int i = 0; i < n_lines; i++) { var se = _lines[i]; result.AddResult((char *)se.GetUnsafePtr(), se.Length); line_count++; } _lines.RemoveRange(0, n_lines); } return(line_count); }