Use union for DreamValue
See original GitHub issueUsing a union would allow you to avoid all boxing operations with DreamValue. Layout would look something like this:
[StructLayout(LayoutKind.Explicit)]
struct DreamValue
{
[Flags]
public enum DreamValueType : byte {
String = 1,
Integer = 2,
Float = 4,
Number = Integer | Float,
DreamResource = 8,
DreamObject = 16,
DreamPath = 32,
DreamProc = 64
}
[FieldOffset(0)]
public DreamValueType Type { get; private set; }
[FieldOffset(4)]
public float FloatValue { get; private set; }
[FieldOffset(4)]
public int IntValue { get; private set; }
[FieldOffset(8)]
public object RefValue { get; private set; }
public DreamValue(String value)
{
Unsafe.SkipInit(out this);
RefValue = value;
IntValue = default;
Type = DreamValueType.String;
}
public DreamValue(int value)
{
Unsafe.SkipInit(out this);
RefValue = default;
IntValue = value;
Type = DreamValueType.Integer;
}
public DreamValue(int value)
{
Unsafe.SkipInit(out this);
RefValue = default;
FloatValue = value;
Type = DreamValueType.Float;
}
public DreamValue(UInt32 value) : this((int) value)
{
}
}
It does beg the question though: why do you allow storing an int in DreamValue? It’s not a real data type in DM and it sounds like it would only complicate the code. This wouldn’t be necessary if DreamValue stores only floats.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
SQL UNION overview, usage and examples
This article will provide a deep dive into the SQL Union operator, describing its many uses along with examples and explore some common ......
Read more >Northern Inland Credit Union Dream Value Home Loan - Mozo
Looking to get more information on the Northern Inland Credit Union Dream Value Home Loan? Find all the product details, interest rates, real...
Read more >Dream Value Home Loan
This home loan package includes all the important features – no establishment fee, 100% offset account and a discounted rate off the standard...
Read more >UNION, INTERSECT, and EXCEPT - Amazon Redshift
The UNION, INTERSECT, and EXCEPT set operators are used to compare and merge the results of two separate query expressions. For example, if...
Read more >Use a union query to combine multiple queries into ...
Get a combined view of multiple select queries with a union query. ... You can't create or use a union query in Access...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@ZeWaka since you were looking into boxing memes
The idea of making DreamValue into a union is no longer relevant since these are now the only two fields on it, and boxing is not as much of a concern anymore.