<html dir="ltr"><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta content="MSHTML 6.00.2900.3243" name="GENERATOR">
<style title="owaParaStyle">P {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
</style>
</head>
<body ocsi="x">
<div dir="ltr"><font color="#000000">Consider the following Ruby code:</font></div>
<div dir="ltr"> </div>
<div dir="ltr">i = 0</div>
<div dir="ltr">while (i < 1000)</div>
<div dir="ltr"> i = i + 1</div>
<div dir="ltr">end</div>
<div dir="ltr"> </div>
<div dir="ltr">When run using IronRuby, the (i < 1000) comparison results in method ConvertToInt32 being invoked to convert local i into an integer, however, the i +1 operation simply casts i to be an integer.</div>
<div dir="ltr"> </div>
<div dir="ltr">(IronPython performs a cast in both cases to avoid the method call to ConvertToInt32)</div>
<div dir="ltr"> </div>
<div dir="ltr">It appears that the difference in behaviour of these two method calls in IronRuby is due to the fact that the first argument for the LessThan method is not overloaded:</div>
<div dir="ltr"><font color="#0000ff">
<p> public</font> <font color="#0000ff">static</font> <font color="#0000ff">bool</font> LessThan(<font color="#0000ff">int</font> self,
<font color="#0000ff">int</font> other)</p>
<font size="2"><font color="#0000ff">
<p><font size="3"> public</font></font><font size="3"> <font color="#0000ff">static</font>
<font color="#0000ff">bool</font> LessThan(<font color="#008080">CodeContext</font><font color="#008000">/*!*/</font> context,
<font color="#0000ff">int</font> self, <font color="#0000ff">object</font> other)</font></p>
<p><font size="3"></font> </p>
<p><font size="3">but the first argument for the Add method is overloaded:</font></p>
<font size="2"><font color="#0000ff">
<p><font size="3"> public</font></font><font size="3"> <font color="#0000ff">static</font>
<font color="#0000ff">object</font> Add(<font color="#0000ff">int</font> self, <font color="#0000ff">
int</font> other)</font></p>
<font size="2"><font color="#0000ff">
<p><font size="3"> public</font></font><font size="3"> <font color="#0000ff">static</font>
<font color="#0000ff">double</font> Add(<font color="#0000ff">int</font> self, <font color="#0000ff">
double</font> other)</font></p>
<font size="2"><font color="#0000ff">
<p><font size="3"> public</font></font><font size="3"> <font color="#0000ff">static</font>
<font color="#0000ff">object</font> Add(<font color="#008080">CodeContext</font><font color="#008000">/*!*/</font> context,
<font color="#0000ff">object</font> self, <font color="#0000ff">object</font> other)</font></p>
<p><font face="times new roman" size="3"></font> </p>
<p><font size="3">Note, this only affects performance, not correctness. Eliminating the call to ConvertToInt32 makes the program execute about 10% faster.</font></p>
<p><font size="3"></font> </p>
<p><font size="3">As an aside, is there really a need for an overloaded Add method with a self of type object rather than int?</font></p>
<p><font size="3">Ironically, making the types stronger in this way would make the performance worse with the current implementation.</font></p>
<p><font size="3"></font> </p>
<p><font size="3">Or am I completely mistaken?</font></p>
<p><font size="3"></font> </p>
<p><font size="3">Cheers, Wayne.</font></p>
<p><font size="2"> </p>
</font></font></font></font></font></div>
</body>
</html>