Skip to content

Commit 8556147

Browse files
committed
Use static data optimisation.
1 parent 7082ca7 commit 8556147

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/MySqlConnector/MySql.Data.MySqlClient/MySqlParameter.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ internal void AppendSqlString(ByteBufferWriter writer, StatementPreparerOptions
215215

216216
if (Value is null || Value == DBNull.Value)
217217
{
218-
writer.Write(s_nullBytes);
218+
writer.Write(NullBytes);
219219
}
220220
else if (Value is string stringValue)
221221
{
@@ -288,16 +288,16 @@ internal void AppendSqlString(ByteBufferWriter writer, StatementPreparerOptions
288288
((ReadOnlyMemory<byte>) Value).Span;
289289

290290
// determine the number of bytes to be written
291-
var length = inputSpan.Length + s_binaryBytes.Length + 1;
291+
var length = inputSpan.Length + BinaryBytes.Length + 1;
292292
foreach (var by in inputSpan)
293293
{
294294
if (by == 0x27 || by == 0x5C)
295295
length++;
296296
}
297297

298298
var outputSpan = writer.GetSpan(length);
299-
s_binaryBytes.CopyTo(outputSpan);
300-
var index = s_binaryBytes.Length;
299+
BinaryBytes.CopyTo(outputSpan);
300+
var index = BinaryBytes.Length;
301301
foreach (var by in inputSpan)
302302
{
303303
if (by == 0x27 || by == 0x5C)
@@ -310,7 +310,7 @@ internal void AppendSqlString(ByteBufferWriter writer, StatementPreparerOptions
310310
}
311311
else if (Value is bool boolValue)
312312
{
313-
writer.Write(boolValue ? s_trueBytes : s_falseBytes);
313+
writer.Write(boolValue ? TrueBytes : FalseBytes);
314314
}
315315
else if (Value is float || Value is double)
316316
{
@@ -373,7 +373,7 @@ internal void AppendSqlString(ByteBufferWriter writer, StatementPreparerOptions
373373
Utility.SwapBytes(bytes, 1, 3);
374374
}
375375
}
376-
writer.Write(s_binaryBytes);
376+
writer.Write(BinaryBytes);
377377
foreach (var by in bytes)
378378
{
379379
if (by == 0x27 || by == 0x5C)
@@ -682,10 +682,10 @@ private static void WriteTime(ByteBufferWriter writer, TimeSpan timeSpan)
682682
}
683683
}
684684

685-
static readonly byte[] s_nullBytes = { 0x4E, 0x55, 0x4C, 0x4C }; // NULL
686-
static readonly byte[] s_trueBytes = { 0x74, 0x72, 0x75, 0x65 }; // true
687-
static readonly byte[] s_falseBytes = { 0x66, 0x61, 0x6C, 0x73, 0x65 }; // false
688-
static readonly byte[] s_binaryBytes = { 0x5F, 0x62, 0x69, 0x6E, 0x61, 0x72, 0x79, 0x27 }; // _binary'
685+
static ReadOnlySpan<byte> NullBytes => new byte[] { 0x4E, 0x55, 0x4C, 0x4C }; // NULL
686+
static ReadOnlySpan<byte> TrueBytes => new byte[] { 0x74, 0x72, 0x75, 0x65 }; // true
687+
static ReadOnlySpan<byte> FalseBytes => new byte[] { 0x66, 0x61, 0x6C, 0x73, 0x65 }; // false
688+
static ReadOnlySpan<byte> BinaryBytes => new byte[] { 0x5F, 0x62, 0x69, 0x6E, 0x61, 0x72, 0x79, 0x27 }; // _binary'
689689

690690
DbType m_dbType;
691691
MySqlDbType m_mySqlDbType;

0 commit comments

Comments
 (0)