Last active
November 22, 2021 06:22
-
-
Save arphox/6363eca76a992504ec3fb8ac854a7aca to your computer and use it in GitHub Desktop.
InternalHasFlag C++ implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// preform (this & flags) != flags | |
FCIMPL2(FC_BOOL_RET, ReflectionEnum::InternalHasFlag, Object *pRefThis, Object* pRefFlags) | |
{ | |
FCALL_CONTRACT; | |
VALIDATEOBJECT(pRefThis); | |
BOOL cmp = false; | |
_ASSERTE(pRefFlags != NULL); // Enum.cs would have thrown ArgumentNullException before calling into InternalHasFlag | |
VALIDATEOBJECT(pRefFlags); | |
void * pThis = pRefThis->UnBox(); | |
void * pFlags = pRefFlags->UnBox(); | |
MethodTable* pMTThis = pRefThis->GetMethodTable(); | |
_ASSERTE(!pMTThis->IsArray()); // bunch of assumptions about arrays wrong. | |
_ASSERTE(pMTThis->GetNumInstanceFieldBytes() == pRefFlags->GetMethodTable()->GetNumInstanceFieldBytes()); // Enum.cs verifies that the types are Equivalent | |
switch (pMTThis->GetNumInstanceFieldBytes()) { | |
case 1: | |
cmp = ((*(UINT8*)pThis & *(UINT8*)pFlags) == *(UINT8*)pFlags); | |
break; | |
case 2: | |
cmp = ((*(UINT16*)pThis & *(UINT16*)pFlags) == *(UINT16*)pFlags); | |
break; | |
case 4: | |
cmp = ((*(UINT32*)pThis & *(UINT32*)pFlags) == *(UINT32*)pFlags); | |
break; | |
case 8: | |
cmp = ((*(UINT64*)pThis & *(UINT64*)pFlags) == *(UINT64*)pFlags); | |
break; | |
default: | |
// should not reach here. | |
UNREACHABLE_MSG("Incorrect Enum Type size!"); | |
break; | |
} | |
FC_RETURN_BOOL(cmp); | |
} | |
FCIMPLEND |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shared on Medium, don't delete!