Skip to content

Commit 83af035

Browse files
committed
DataType GetByName reduced memory allocations by switching from string to span.
1 parent ba48adf commit 83af035

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

SqlServerSimulator/DataType.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ private protected DataType()
4242
/// <exception cref="SimulatedSqlException">Column, parameter, or variable #<paramref name="index"/>: Cannot find data type <paramref name="name"/>.</exception>
4343
public static DataType GetByName(Name name, int index)
4444
{
45-
Span<char> upper = stackalloc char[name.Value.Length];
46-
return name.Value.ToUpperInvariant(upper) switch
45+
Span<char> upper = stackalloc char[name.Span.Length];
46+
return name.Span.ToUpperInvariant(upper) switch
4747
{
4848
3 => upper switch
4949
{
@@ -62,7 +62,7 @@ public static DataType GetByName(Name name, int index)
6262
_ => null
6363
},
6464
_ => null,
65-
} ?? throw SimulatedSqlException.CannotFindDataType(name.Value, index);
65+
} ?? throw SimulatedSqlException.CannotFindDataType(name.Span, index);
6666
}
6767

6868
public static DataType GetByDbType(DbType dbType) => dbType switch

SqlServerSimulator/SimulatedSqlException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private SimulatedSqlException(string? message, params ReadOnlySpan<SimulatedSqlE
9090
/// <param name="name">The name of the type.</param>
9191
/// <param name="index">The 1-based index of the reference.</param>
9292
/// <returns>The exception.</returns>
93-
internal static SimulatedSqlException CannotFindDataType(string name, int index) => new($"Column, parameter, or variable #{index}: Cannot find data type {name}.", 2715, 16, 6);
93+
internal static SimulatedSqlException CannotFindDataType(ReadOnlySpan<char> name, int index) => new($"Column, parameter, or variable #{index}: Cannot find data type {name}.", 2715, 16, 6);
9494

9595
/// <summary>
9696
/// Mimics the SqlException that occurs then when a TOP/OFFSET/FETCH clause has an inappropriate column reference.

0 commit comments

Comments
 (0)