-
Notifications
You must be signed in to change notification settings - Fork 316
Move into shared for SqlCachedBuffer.cs #1280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
0a7d82e
a183f01
7520331
986fe1c
500c4a0
7dd8488
fac9f00
65f6488
043764b
ee8f9f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() | ||
| { | ||
|
|
@@ -32,21 +32,19 @@ private SqlCachedBuffer(List<byte[]> cachedBytes) | |
|
|
||
| internal List<byte[]> CachedBytes | ||
| { | ||
| get { return _cachedBytes; } | ||
| get => _cachedBytes; | ||
| } | ||
|
||
|
|
||
| // Reads off from the network buffer and caches bytes. Only reads one column value in the current row. | ||
lcheunglci marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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; | ||
| } | ||
|
|
@@ -58,7 +56,7 @@ internal static bool TryCreate(SqlMetaDataPriv metadata, TdsParser parser, TdsPa | |
| break; | ||
lcheunglci marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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)) | ||
| { | ||
|
|
@@ -111,7 +109,7 @@ override public string ToString() | |
| { | ||
| return string.Empty; | ||
| } | ||
| SqlXml sxml = new SqlXml(ToStream()); | ||
| SqlXml sxml = new(ToStream()); | ||
| return sxml.Value; | ||
| } | ||
|
|
||
|
|
@@ -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; | ||
|
||
| } | ||
|
|
||
|
|
||
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.