[Mono-devel-list] Inefficiencies in mcs

Andreas Nahr ClassDevelopment at A-SoftTech.com
Tue Feb 24 13:08:04 EST 2004


Hi,

just in case these are not known I found some inefficiencies in the mcs -
generated IL.

The following code (Taken from convert class)

public static bool ToBoolean(bool value)
{
return value;
}

compiles into this (Mono .30):

public static bool ToBoolean(bool value);

.maxstack 8
L_0000: ldarg.0
L_0001: ret

obviously .maxstack should be 1


another thing: The following code

  public int CompareTo (object obj)
  {
   if (obj == null)
    return 1;

   if (!(obj is System.BooleanT))
    throw new ArgumentException
    (Locale.GetText ("Object is not a Boolean and is not a null
reference"));

   // for case #3
   bool objval = (bool)obj;
   if (value && objval == false)
    return 1;

   // for case #2, else it's #1
   return (value == objval) ? 0 : -1;
  }

compiles into this (Mono .30):

public int CompareTo(object obj)
{
bool flag1;
int num1;
if (obj == null)
{
 num1 = 1;

}
else
{ if ((obj as BooleanT) == 0)
{
 throw new ArgumentException(Locale.GetText("Object is not a Boolean and is
not a null reference"));

}
flag1 = ((bool) obj);
if (this.value && !flag1)
{
 num1 = 1;
goto L_0061;

}
num1 = ((this.value != flag1) ? -1 : 0);

}

L_0061:
 return num1;
}

Which intoduces an excess variable of type int and handles all return cases
at the end instead of immediately doing an constant int - return (which
should be faster)




More information about the Mono-devel-list mailing list