adjust some TODOs in ParsingPrimitives.cs

This commit is contained in:
Jan Tattermusch 2020-04-22 10:03:51 +02:00
parent dd97af88db
commit eb38a3cdb8

View File

@ -558,12 +558,13 @@ namespace Google.Protobuf
} }
else else
{ {
// TODO: do we need to support skipping in seekable Streams?
// Skipping more bytes than are in the buffer. First skip what we have. // Skipping more bytes than are in the buffer. First skip what we have.
int pos = state.bufferSize - state.bufferPos; int pos = state.bufferSize - state.bufferPos;
state.bufferPos = state.bufferSize; state.bufferPos = state.bufferSize;
// TODO: If our segmented buffer is backed by a Stream that is seekable, we could skip the bytes more efficiently
// by simply updating stream's Position property. This used to be supported in the past, but the support was dropped
// because it would make the segmentedBufferHelper more complex. Support can be reintroduced if needed.
state.segmentedBufferHelper.RefillBuffer(ref buffer, ref state, true); state.segmentedBufferHelper.RefillBuffer(ref buffer, ref state, true);
while (size - pos > state.bufferSize) while (size - pos > state.bufferSize)
@ -637,18 +638,16 @@ namespace Google.Protobuf
} }
#endif #endif
// TODO: what if GOOGLE_PROTOBUF_SUPPORT_FAST_STRING is not supported? var decoder = CodedOutputStream.Utf8Encoding.GetDecoder();
// -> can we still try to grab an array from the span?
// if (length <= state.bufferSize - state.bufferPos && length > 0) // TODO: even if GOOGLE_PROTOBUF_SUPPORT_FAST_STRING is not supported,
// { // we could still create a string efficiently by using Utf8Encoding.GetString(byte[] bytes, int index, int count)
// // Fast path: We already have the bytes in a contiguous buffer, so // whenever the buffer is backed by a byte array (and avoid creating a new byte array), but the problem is
// // just copy directly from it. // there is no way to get the underlying byte array from a span.
// String result = CodedOutputStream.Utf8Encoding.GetString(buffer, state.bufferPos, length);
// state.bufferPos += length; // TODO: in case the string spans multiple buffer segments, creating a char[] and decoding into it and then
// return result; // creating a string from that array might be more efficient than creating a string from the copied bytes.
// }
// TODO: creating a char[] and decoding into it and then creating a string from that array might be more efficient
// Slow path: Build a byte array first then copy it. // Slow path: Build a byte array first then copy it.
return CodedOutputStream.Utf8Encoding.GetString(ReadRawBytes(ref buffer, ref state, length), 0, length); return CodedOutputStream.Utf8Encoding.GetString(ReadRawBytes(ref buffer, ref state, length), 0, length);
} }