Skip to content

Commit ca3bdf5

Browse files
authored
Merge pull request #786 from danielgindi/perf/happy_flow
Sort out happy flows for fastest execution for expected types.
2 parents 65c5735 + dbc2d19 commit ca3bdf5

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/MySqlConnector/Core/Row.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,22 +353,38 @@ public Stream GetStream(int ordinal)
353353
public decimal GetDecimal(int ordinal)
354354
{
355355
var value = GetValue(ordinal);
356-
return value is float floatValue ? (decimal) floatValue :
357-
value is double decimalValue ? (decimal) decimalValue :
358-
(decimal) value;
356+
if (value is decimal) // happy flow
357+
return (decimal) value;
358+
359+
if (value is double doubleValue)
360+
return (decimal) doubleValue;
361+
362+
if (value is float floatValue)
363+
return (decimal) floatValue;
364+
365+
return (decimal) value;
359366
}
360367

361368
public double GetDouble(int ordinal)
362369
{
363370
var value = GetValue(ordinal);
364-
return value is float floatValue ? floatValue :
365-
value is decimal decimalValue ? (double) decimalValue :
366-
(double) value;
371+
if (value is double) // happy flow
372+
return (double) value;
373+
374+
if (value is float floatValue)
375+
return floatValue;
376+
377+
if (value is decimal decimalValue)
378+
return (double) decimalValue;
379+
380+
return (double) value;
367381
}
368382

369383
public float GetFloat(int ordinal)
370384
{
371385
var value = GetValue(ordinal);
386+
if (value is float) // happy flow
387+
return (float) value;
372388

373389
// Loss of precision is expected, significant loss of information is not.
374390
// Use explicit range checks to guard against that.

0 commit comments

Comments
 (0)