Skip to content

Commit b24f5d6

Browse files
authored
More improvements in ObjectsEqual (#2839)
1 parent b3e27ad commit b24f5d6

File tree

1 file changed

+14
-48
lines changed

1 file changed

+14
-48
lines changed

src/CLR/Core/CLR_RT_HeapBlock.cpp

Lines changed: 14 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,19 @@ bool CLR_RT_HeapBlock::ObjectsEqual(
13151315
break;
13161316

13171317
case DATATYPE_STRING:
1318+
case DATATYPE_CLASS:
1319+
case DATATYPE_BOOLEAN:
1320+
case DATATYPE_CHAR:
1321+
case DATATYPE_I1:
1322+
case DATATYPE_U1:
1323+
case DATATYPE_I2:
1324+
case DATATYPE_U2:
1325+
case DATATYPE_I4:
1326+
case DATATYPE_U4:
1327+
case DATATYPE_I8:
1328+
case DATATYPE_U8:
1329+
case DATATYPE_DATETIME:
1330+
case DATATYPE_TIMESPAN:
13181331
return Compare_Values(pArgLeft, pArgRight, false) == 0;
13191332
break;
13201333

@@ -1364,53 +1377,6 @@ bool CLR_RT_HeapBlock::ObjectsEqual(
13641377
}
13651378
break;
13661379

1367-
case DATATYPE_CLASS:
1368-
{
1369-
const CLR_RT_HeapBlock *objLeft = &pArgLeft;
1370-
const CLR_RT_HeapBlock *objRight = &pArgRight;
1371-
1372-
CLR_RT_TypeDef_Instance classLeftObj;
1373-
classLeftObj.InitializeFromIndex(objLeft->ObjectCls());
1374-
CLR_RT_TypeDef_Instance classRightObj;
1375-
classRightObj.InitializeFromIndex(objRight->ObjectCls());
1376-
1377-
if (classLeftObj.m_data == classRightObj.m_data)
1378-
{
1379-
// this has been already checked above, still adding it here for completeness
1380-
if (&pArgLeft == &pArgRight)
1381-
{
1382-
return true;
1383-
}
1384-
1385-
// check if the objects have the same number of fields
1386-
int leftClassTotFields = classLeftObj.CrossReference().m_totalFields;
1387-
int rightClassTotFields = classRightObj.CrossReference().m_totalFields;
1388-
1389-
if (leftClassTotFields > 0 && rightClassTotFields > 0 && leftClassTotFields == rightClassTotFields)
1390-
{
1391-
int equalFieldsCount = 0;
1392-
int totalFieldsCount = leftClassTotFields;
1393-
1394-
// loop through the fields and compare them
1395-
do
1396-
{
1397-
if (ObjectsEqual(
1398-
objLeft[leftClassTotFields + CLR_RT_HeapBlock::HB_Object_Fields_Offset],
1399-
objRight[rightClassTotFields + CLR_RT_HeapBlock::HB_Object_Fields_Offset],
1400-
false))
1401-
{
1402-
// fields are equal
1403-
equalFieldsCount++;
1404-
}
1405-
} while (--leftClassTotFields > 0);
1406-
1407-
// check if all fields are equal
1408-
return equalFieldsCount == totalFieldsCount;
1409-
}
1410-
}
1411-
}
1412-
break;
1413-
14141380
default:
14151381

14161382
if ((leftDataType == rightDataType) && fSameReference == false)
@@ -1686,7 +1652,7 @@ CLR_INT32 CLR_RT_HeapBlock::Compare_Values(const CLR_RT_HeapBlock &left, const C
16861652
// deal with special cases:
16871653
// return 0 if the numbers are unordered (either or both are NaN)
16881654
// this is post processed in interpreter so '1' will turn into '0'
1689-
if (__isnand(left.NumericByRefConst().r4) || __isnand(right.NumericByRefConst().r4))
1655+
if (__isnand(left.NumericByRefConst().r4) && __isnand(right.NumericByRefConst().r4))
16901656
{
16911657
return 1;
16921658
}

0 commit comments

Comments
 (0)