<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-GB link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Regarding the aside, you can pass Float, Bignum, Complex or any
other class you choose to define to the Fixnum#+ operator so you do need an
overload with object.&nbsp; I seem to remember it then coerces the fixnum to
whatever the other type is and then calls + on the coerced object.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Without looking at the code I can&#8217;t comment on the main thrust
of the mail, but shouldn&#8217;t the local variable i be a Fixnum from the word go
and therefore call the LessThan(int, int) method anyway?<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Pete<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<div>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>

<p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:
"Tahoma","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:10.0pt;
font-family:"Tahoma","sans-serif"'> ironruby-core-bounces@rubyforge.org
[mailto:ironruby-core-bounces@rubyforge.org] <b>On Behalf Of </b>Wayne Kelly<br>
<b>Sent:</b> Tuesday,05 February 05, 2008 03:36<br>
<b>To:</b> ironruby-core@rubyforge.org<br>
<b>Subject:</b> [Ironruby-core] ConvertTo vs Cast<o:p></o:p></span></p>

</div>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<div>

<p class=MsoNormal><span style='color:black'>Consider the following Ruby code:</span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>i = 0<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>while (i &lt; 1000)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp; i = i + 1<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>end<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>When run using IronRuby, the (i &lt; 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.<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>(IronPython performs a cast in both cases to avoid the
method call to ConvertToInt32)<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>&nbsp;<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal>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:<o:p></o:p></p>

</div>

<div>

<p><span style='color:blue'>&nbsp; public</span> <span style='color:blue'>static</span>
<span style='color:blue'>bool</span> LessThan(<span style='color:blue'>int</span>
self, <span style='color:blue'>int</span> other)<o:p></o:p></p>

<p><span style='color:blue'>&nbsp; public</span> <span style='color:blue'>static</span>
<span style='color:blue'>bool</span> LessThan(<span style='color:teal'>CodeContext</span><span
style='color:green'>/*!*/</span> context, <span style='color:blue'>int</span>
self, <span style='color:blue'>object</span> other)<span style='font-size:10.0pt'><o:p></o:p></span></p>

<p><span style='font-size:10.0pt'>&nbsp;<o:p></o:p></span></p>

<p>but the first argument for the Add method is overloaded:<span
style='font-size:10.0pt'><o:p></o:p></span></p>

<p><span style='color:blue'>&nbsp; public</span> <span style='color:blue'>static</span>
<span style='color:blue'>object</span> Add(<span style='color:blue'>int</span>
self, <span style='color:blue'>int</span> other)<span style='font-size:10.0pt'><o:p></o:p></span></p>

<p><span style='color:blue'>&nbsp; public</span> <span style='color:blue'>static</span>
<span style='color:blue'>double</span> Add(<span style='color:blue'>int</span>
self, <span style='color:blue'>double</span> other)<span style='font-size:10.0pt'><o:p></o:p></span></p>

<p><span style='color:blue'>&nbsp; public</span> <span style='color:blue'>static</span>
<span style='color:blue'>object</span> Add(<span style='color:teal'>CodeContext</span><span
style='color:green'>/*!*/</span> context, <span style='color:blue'>object</span>
self, <span style='color:blue'>object</span> other)<span style='font-size:10.0pt'><o:p></o:p></span></p>

<p><span style='font-size:10.0pt'>&nbsp;<o:p></o:p></span></p>

<p>Note, this only affects performance, not correctness. Eliminating the call
to ConvertToInt32 makes the program execute about 10% faster.<span
style='font-size:10.0pt'><o:p></o:p></span></p>

<p><span style='font-size:10.0pt'>&nbsp;<o:p></o:p></span></p>

<p>As an aside, is there really a need&nbsp;for an overloaded Add method with a
self of type object rather than int?<span style='font-size:10.0pt'><o:p></o:p></span></p>

<p>Ironically, making the types stronger in this way would make the
performance&nbsp;worse with the current implementation.<span style='font-size:
10.0pt'><o:p></o:p></span></p>

<p><span style='font-size:10.0pt'>&nbsp;<o:p></o:p></span></p>

<p>Or am I completely mistaken?<span style='font-size:10.0pt'><o:p></o:p></span></p>

<p><span style='font-size:10.0pt'>&nbsp;<o:p></o:p></span></p>

<p>Cheers, Wayne.<span style='font-size:10.0pt'><o:p></o:p></span></p>

<p><span style='font-size:10.0pt'>&nbsp;<o:p></o:p></span></p>

</div>

</div>

</body>

</html>