title: Why .NET String.EqualsHelper seems to use half sized integers and longs
body: <p>Looking at the implementation of String.EqualsHelper and String.CompareOrdinalHelper (.NET 2 &amp; 4), it seems to me that the comparisions are assuming that int byte size is 2 and long byte size is 4. I think the real sizes are 4 and 8 in the .NET 32-bit world. What am I missing? Is there any catch here? Source code sample in <a href="https://stackoverflow.com/q/5927545/1320384">A look inside the EqualsHelper method in the .NET framework</a> and <a href="http://www.netframeworkdevs.com/common-language-runtime/string-comparision-24141.shtml" rel="nofollow noreferrer">http://www.netframeworkdevs.com/common-language-runtime/string-comparision-24141.shtml</a>.</p>
  
  <p>Reverse engineered source from Reflector (Framework 2):</p>
  
  <pre><code>[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
  private static unsafe bool EqualsHelper(string strA, string strB)
  {
      int length = strA.Length;
      if (length != strB.Length)
      {
          return false;
      }
      fixed (char* str = ((char*) strA))
      {
          char* chPtr = str;
          fixed (char* str2 = ((char*) strB))
          {
              char* chPtr2 = str2;
              char* chPtr3 = chPtr;
              char* chPtr4 = chPtr2;
              while (length &gt;= 10)
              {
                  if ((((*(((int*) chPtr3)) != *(((int*) chPtr4))) || (*(((int*) (chPtr3 + 2))) != *(((int*) (chPtr4 + 2))))) || ((*(((int*) (chPtr3 + 4))) != *(((int*) (chPtr4 + 4)))) || (*(((int*) (chPtr3 + 6))) != *(((int*) (chPtr4 + 6)))))) || (*(((int*) (chPtr3 + 8))) != *(((int*) (chPtr4 + 8)))))
                  {
                      break;
                  }
                  chPtr3 += 10;
                  chPtr4 += 10;
                  length -= 10;
              }
              while (length &gt; 0)
              {
                  if (*(((int*) chPtr3)) != *(((int*) chPtr4)))
                  {
                      break;
                  }
                  chPtr3 += 2;
                  chPtr4 += 2;
                  length -= 2;
              }
              return (length &lt;= 0);
          }
      }
  }
  
  private static unsafe int CompareOrdinalHelper(string strA, string strB)
  {
      int num = Math.Min(strA.Length, strB.Length);
      int num2 = -1;
      fixed (char* str = ((char*) strA))
      {
          char* chPtr = str;
          fixed (char* str2 = ((char*) strB))
          {
              char* chPtr2 = str2;
              char* chPtr3 = chPtr;
              char* chPtr4 = chPtr2;
              while (num &gt;= 10)
              {
                  if (*(((int*) chPtr3)) != *(((int*) chPtr4)))
                  {
                      num2 = 0;
                      break;
                  }
                  if (*(((int*) (chPtr3 + 2))) != *(((int*) (chPtr4 + 2))))
                  {
                      num2 = 2;
                      break;
                  }
                  if (*(((int*) (chPtr3 + 4))) != *(((int*) (chPtr4 + 4))))
                  {
                      num2 = 4;
                      break;
                  }
                  if (*(((int*) (chPtr3 + 6))) != *(((int*) (chPtr4 + 6))))
                  {
                      num2 = 6;
                      break;
                  }
                  if (*(((int*) (chPtr3 + 8))) != *(((int*) (chPtr4 + 8))))
                  {
                      num2 = 8;
                      break;
                  }
                  chPtr3 += 10;
                  chPtr4 += 10;
                  num -= 10;
              }
              if (num2 == -1)
              {
                  goto Label_0101;
              }
              chPtr3 += num2;
              chPtr4 += num2;
              int num3 = chPtr3[0] - chPtr4[0];
              if (num3 != 0)
              {
                  return num3;
              }
              return (chPtr3[1] - chPtr4[1]);
          Label_00E7:
              if (*(((int*) chPtr3)) != *(((int*) chPtr4)))
              {
                  goto Label_0105;
              }
              chPtr3 += 2;
              chPtr4 += 2;
              num -= 2;
          Label_0101:
              if (num &gt; 0)
              {
                  goto Label_00E7;
              }
          Label_0105:
              if (num &gt; 0)
              {
                  int num4 = chPtr3[0] - chPtr4[0];
                  if (num4 != 0)
                  {
                      return num4;
                  }
                  return (chPtr3[1] - chPtr4[1]);
              }
              return (strA.Length - strB.Length);
          }
      }
  }
  </code></pre>