No nonsense union.

This commit is contained in:
Bartosz Taudul 2018-03-04 17:52:51 +01:00
parent 5afdccfc46
commit 5cb917e868
2 changed files with 9 additions and 19 deletions

View File

@ -17,27 +17,16 @@ struct StringRef
{ {
enum Type { Ptr, Idx }; enum Type { Ptr, Idx };
StringRef() : strptr( 0 ), __data( 0 ) {} StringRef() : str( 0 ), __data( 0 ) {}
StringRef( Type t, uint64_t data ) : __data( 0 ) StringRef( Type t, uint64_t data )
: str( data )
, __data( 0 )
{ {
isidx = t == Idx; isidx = t == Idx;
active = 1; active = 1;
if( isidx )
{
stridx = data;
}
else
{
strptr = data;
}
} }
union uint64_t str;
{
uint64_t strptr;
uint64_t stridx;
};
union union
{ {
@ -53,7 +42,8 @@ struct StringRef
struct StringIdx struct StringIdx
{ {
StringIdx() : __data( 0 ) {} StringIdx() : __data( 0 ) {}
StringIdx( uint32_t _idx ) : __data( 0 ) StringIdx( uint32_t _idx )
: __data( 0 )
{ {
idx = _idx; idx = _idx;
active = 1; active = 1;

View File

@ -325,13 +325,13 @@ const char* Worker::GetString( const StringRef& ref ) const
if( ref.isidx ) if( ref.isidx )
{ {
assert( ref.active ); assert( ref.active );
return m_data.stringData[ref.stridx]; return m_data.stringData[ref.str];
} }
else else
{ {
if( ref.active ) if( ref.active )
{ {
return GetString( ref.strptr ); return GetString( ref.str );
} }
else else
{ {