<div class="gmail_quote">On Fri, Aug 3, 2012 at 8:28 AM, jerro <span dir="ltr"><<a href="mailto:a@a.com" target="_blank">a@a.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On Sunday, 29 July 2012 at 20:24:42 UTC, Dmitry Olshansky wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 30-Jul-12 00:11, Dmitry Olshansky wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I've found something far more evil:<br>
<br>
@property bool convertsTo(T)() const<br>
{<br>
TypeInfo info = typeid(T);<br>
return fptr(OpID.testConversion, null, &info) == 0;<br>
}<br>
<br>
Okay... now let me pull off another piece of rag:<br>
<br>
private VariantN opArithmetic(T, string op)(T other)<br>
{<br>
VariantN result;<br>
static if (is(T == VariantN))<br>
{<br>
/*if (convertsTo!(uint) && other.convertsTo!(uint))<br>
result = mixin("get!(uint) " ~ op ~ " other.get!(uint)");<br>
else*/ if (convertsTo!(int) && other.convertsTo!(int))<br>
result = mixin("get!(int) " ~ op ~ " other.get!(int)");<br>
</blockquote>
...<br>
Apparently I'm spot on.<br>
Just commenting one extra branch of this horror movie<br>
gives interesting change:<br>
<br>
2779us<br>
2667us<br>
3153762us<br>
<br>
After:<br>
<br>
2319us<br>
2523us<br>
288581us<br>
<br>
Aye, 10x :o)<br>
</blockquote>
<br></div></div>
I profiled it and found out much of the time is spent inside TypeInfo.opEquals being called from tryPutting. So I tried replacing "!= typeid" in tryPutting with "!is typeid". That brought the time from 2.8 s down to 0.12 on my machine. I don't know if that is the proper solution, since I don't know if typeid can ever return two TypeInfo objects that aren't the same but are equal (I haven't used typeid and TypeInfo much before). The fib function here does return correct result after doing that, though.<br>
</blockquote></div><br>Wow! Now that's an impressive improvement. If TypeInfo instances are unique for every type, then we should be good to go!<br clear="all"><div><br></div>-- <br>Bye,<br>Gor Gyolchanyan.<br>