Skip to content

Sort out happy flows for fastest execution for expected types #786

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

Merged
merged 1 commit into from
Mar 25, 2020
Merged
Changes from all 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
28 changes: 22 additions & 6 deletions src/MySqlConnector/Core/Row.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,22 +353,38 @@ public Stream GetStream(int ordinal)
public decimal GetDecimal(int ordinal)
{
var value = GetValue(ordinal);
return value is float floatValue ? (decimal) floatValue :
value is double decimalValue ? (decimal) decimalValue :
(decimal) value;
if (value is decimal) // happy flow
return (decimal) value;

if (value is double doubleValue)
return (decimal) doubleValue;

if (value is float floatValue)
return (decimal) floatValue;

return (decimal) value;
}

public double GetDouble(int ordinal)
{
var value = GetValue(ordinal);
return value is float floatValue ? floatValue :
value is decimal decimalValue ? (double) decimalValue :
(double) value;
if (value is double) // happy flow
return (double) value;

if (value is float floatValue)
return floatValue;

if (value is decimal decimalValue)
return (double) decimalValue;

return (double) value;
}

public float GetFloat(int ordinal)
{
var value = GetValue(ordinal);
if (value is float) // happy flow
return (float) value;

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