Skip to content
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

Optimize unboxing in System.Data.Common.ObjectStorage:Set #91945

Closed
wants to merge 3 commits into from
Closed
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -226,73 +226,89 @@ public override bool IsNull(int record)
public override void Set(int recordNo, object value)
{
Debug.Assert(null != value, "null value");

if (_nullValue == value)
{
_values[recordNo] = null;
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the aim behind replacing else blocks with many duplicated returns?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To use a single throw at the end of the method whilst keeping the control flow simple. The JIT will create a single exit.

If this is less readable I can revert to else blocks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MihaZupan What is your view on this?

}
else if (_dataType == typeof(object) || _dataType.IsInstanceOfType(value))

if (_dataType == typeof(object) || value.GetType() == typeof(object))
{
_values[recordNo] = value;
return;
}
else

if (_dataType == typeof(Guid) && value.GetType() == typeof(string))
{
_values[recordNo] = new Guid((string)value);
return;
}

if (_dataType == typeof(byte[]))
{
Type valType = value.GetType();
if (_dataType == typeof(Guid) && valType == typeof(string))
if (value.GetType() == typeof(bool))
{
_values[recordNo] = new Guid((string)value);
_values[recordNo] = BitConverter.GetBytes((bool)value);
return;
}
else if (_dataType == typeof(byte[]))

if (value.GetType() == typeof(char))
{
if (valType == typeof(bool))
{
_values[recordNo] = BitConverter.GetBytes((bool)value);
}
else if (valType == typeof(char))
{
_values[recordNo] = BitConverter.GetBytes((char)value);
}
else if (valType == typeof(short))
{
_values[recordNo] = BitConverter.GetBytes((short)value);
}
else if (valType == typeof(int))
{
_values[recordNo] = BitConverter.GetBytes((int)value);
}
else if (valType == typeof(long))
{
_values[recordNo] = BitConverter.GetBytes((long)value);
}
else if (valType == typeof(ushort))
{
_values[recordNo] = BitConverter.GetBytes((ushort)value);
}
else if (valType == typeof(uint))
{
_values[recordNo] = BitConverter.GetBytes((uint)value);
}
else if (valType == typeof(ulong))
{
_values[recordNo] = BitConverter.GetBytes((ulong)value);
}
else if (valType == typeof(float))
{
_values[recordNo] = BitConverter.GetBytes((float)value);
}
else if (valType == typeof(double))
{
_values[recordNo] = BitConverter.GetBytes((double)value);
}
else
{
throw ExceptionBuilder.StorageSetFailed();
}
_values[recordNo] = BitConverter.GetBytes((char)value);
return;
}
else

if (value.GetType() == typeof(short))
{
_values[recordNo] = BitConverter.GetBytes((short)value);
return;
}

if (value.GetType() == typeof(int))
{
_values[recordNo] = BitConverter.GetBytes((int)value);
return;
}

if (value.GetType() == typeof(long))
{
_values[recordNo] = BitConverter.GetBytes((long)value);
return;
}

if (value.GetType() == typeof(ushort))
{
throw ExceptionBuilder.StorageSetFailed();
_values[recordNo] = BitConverter.GetBytes((ushort)value);
return;
}

if (value.GetType() == typeof(uint))
{
_values[recordNo] = BitConverter.GetBytes((uint)value);
return;
}

if (value.GetType() == typeof(ulong))
{
_values[recordNo] = BitConverter.GetBytes((ulong)value);
return;
}

if (value.GetType() == typeof(float))
{
_values[recordNo] = BitConverter.GetBytes((float)value);
return;
}

if (value.GetType() == typeof(double))
{
_values[recordNo] = BitConverter.GetBytes((double)value);
return;
}
}

throw ExceptionBuilder.StorageSetFailed();
}

public override void SetCapacity(int capacity)
Expand Down