KalleOlaviNiemitalo commented on code in PR #2439:
URL: https://github.com/apache/avro/pull/2439#discussion_r1306652260
##########
lang/csharp/src/apache/main/Generic/GenericReader.cs:
##########
@@ -297,8 +297,6 @@ protected virtual object ReadRecord(object reuse,
RecordSchema writerSchema, Sch
var defaultDecoder = new BinaryDecoder(defaultStream);
foreach (Field rf in rs.Fields.Where(rf =>
!writerSchema.Contains(rf.Name)))
Review Comment:
I expect this change makes the code slower, as it now has to allocate a
closure and a delegate, and the calls become indirect too. Roslyn contribution
guidelines advise "Avoid LINQ" for that reason. So I'd prefer reverting this
and disabling the CodeQL warning.
*
<https://github.com/dotnet/roslyn/blob/34268d1bb9370c7b01c742303a895a99daf10d6a/CONTRIBUTING.md?plain=1#L83>
*
<https://stackoverflow.com/questions/22894877/avoid-allocations-in-compiler-hot-paths-roslyn-coding-conventions>
##########
lang/csharp/src/apache/main/File/DeflateCodec.cs:
##########
@@ -58,32 +58,14 @@ public override void Compress(MemoryStream inputStream,
MemoryStream outputStrea
/// <inheritdoc/>
public override byte[] Decompress(byte[] compressedData, int length)
{
-
- MemoryStream inStream = new MemoryStream(compressedData);
- MemoryStream outStream = new MemoryStream();
-
- using (DeflateStream Decompress =
- new DeflateStream(inStream,
- CompressionMode.Decompress))
- {
- CopyTo(Decompress, outStream);
- }
-
- return outStream.ToArray();
- }
-
- /// <summary>
- /// Copies to stream.
- /// </summary>
- /// <param name="from">stream you are copying from</param>
- /// <param name="to">stream you are copying to</param>
- private static void CopyTo(Stream from, Stream to)
- {
- byte[] buffer = new byte[4096];
- int read;
- while ((read = from.Read(buffer, 0, buffer.Length)) != 0)
+ using (MemoryStream inStream = new MemoryStream(compressedData, 0,
length))
Review Comment:
Could make `MemoryStream inStream` read-only by [constructing
it](https://learn.microsoft.com/dotnet/api/system.io.memorystream.-ctor#system-io-memorystream-ctor(system-byte()-system-int32-system-int32-system-boolean))
with `writable: false` (the default is `true`). Not important though, as
DeflateStream with CompressionMode.Decompress won't try to write to it anyway.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]