Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlBulkCopyColumnOrderHintCollection.cs">
<Link>Microsoft\Data\SqlClient\SqlBulkCopyColumnOrderHintCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlCachedBuffer.cs">
<Link>Microsoft\Data\SqlClient\SqlCachedBuffer.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlClientEncryptionAlgorithm.cs">
<Link>Microsoft\Data\SqlClient\SqlClientEncryptionAlgorithm.cs</Link>
</Compile>
Expand Down Expand Up @@ -481,7 +484,6 @@
<Compile Include="Microsoft\Data\SqlClient\SqlBuffer.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlBulkCopy.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlBulkCopyColumnMappingCollection.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlCachedBuffer.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlClientDiagnosticListenerExtensions.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlClientFactory.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlCommand.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlBulkCopyColumnOrderHintCollection.cs">
<Link>Microsoft\Data\SqlClient\SqlBulkCopyColumnOrderHintCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlCachedBuffer.cs">
<Link>Microsoft\Data\SqlClient\SqlCachedBuffer.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlClientEncryptionAlgorithm.cs">
<Link>Microsoft\Data\SqlClient\SqlClientEncryptionAlgorithm.cs</Link>
</Compile>
Expand Down Expand Up @@ -438,7 +441,6 @@
<Compile Include="Microsoft\Data\SqlClient\SqlBuffer.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlBulkCopy.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlBulkCopyColumnMappingCollection.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlCachedBuffer.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlCertificateCallbacks.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlClientFactory.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlClientOriginalAddressInfo.cs" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ namespace Microsoft.Data.SqlClient
// Caches the bytes returned from partial length prefixed datatypes, like XML
sealed internal class SqlCachedBuffer : System.Data.SqlTypes.INullable
{
public static readonly SqlCachedBuffer Null = new SqlCachedBuffer();
private const int _maxChunkSize = 2048; // Arbitrary value for chunk size. Revisit this later for better perf
public static readonly SqlCachedBuffer Null = new();
private const int MaxChunkSize = 2048; // Arbitrary value for chunk size. Revisit this later for better perf

private List<byte[]> _cachedBytes;
private readonly List<byte[]> _cachedBytes;

private SqlCachedBuffer()
{
Expand All @@ -32,21 +32,19 @@ private SqlCachedBuffer(List<byte[]> cachedBytes)

internal List<byte[]> CachedBytes
{
get { return _cachedBytes; }
get => _cachedBytes;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: This way it would be neater.
internal List<byte[]> CachedBytes => _cachedBytes;


// Reads off from the network buffer and caches bytes. Only reads one column value in the current row.
internal static bool TryCreate(SqlMetaDataPriv metadata, TdsParser parser, TdsParserStateObject stateObj, out SqlCachedBuffer buffer)
{
int cb = 0;
ulong plplength;
byte[] byteArr;

List<byte[]> cachedBytes = new List<byte[]>();
List<byte[]> cachedBytes = new();
buffer = null;

// the very first length is already read.
if (!parser.TryPlpBytesLeft(stateObj, out plplength))
if (!parser.TryPlpBytesLeft(stateObj, out ulong plplength))
{
return false;
}
Expand All @@ -58,7 +56,7 @@ internal static bool TryCreate(SqlMetaDataPriv metadata, TdsParser parser, TdsPa
break;
do
{
cb = (plplength > (ulong)_maxChunkSize) ? _maxChunkSize : (int)plplength;
int cb = (plplength > (ulong)MaxChunkSize) ? MaxChunkSize : (int)plplength;
byteArr = new byte[cb];
if (!stateObj.TryReadPlpBytes(ref byteArr, 0, cb, out cb))
{
Expand Down Expand Up @@ -111,7 +109,7 @@ override public string ToString()
{
return string.Empty;
}
SqlXml sxml = new SqlXml(ToStream());
SqlXml sxml = new(ToStream());
return sxml.Value;
}

Expand All @@ -125,23 +123,13 @@ internal SqlString ToSqlString()

internal SqlXml ToSqlXml()
{
SqlXml sx = new SqlXml(ToStream());
SqlXml sx = new(ToStream());
return sx;
}

// Prevent inlining so that reflection calls are not moved to caller that may be in a different assembly that may have a different grant set.
[MethodImpl(MethodImplOptions.NoInlining)]
internal XmlReader ToXmlReader()
{
return SqlTypeWorkarounds.SqlXmlCreateSqlXmlReader(ToStream(), closeInput: false);
}

public bool IsNull
{
get
{
return (_cachedBytes == null) ? true : false;
}
get => _cachedBytes == null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: It would be simpler using expression body syntax:
public bool IsNull => _cachedBytes is null;

}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra lines; could be removed.

Expand Down