code generalization

Saaa empty at needmail.com
Mon Jun 8 16:08:55 PDT 2009


I just finished my array parser but I can't support just any depth because 
each depth needs its own code the way I am doing it now :(
Also, as you can see, I am using a doubling strategy to minimize the amount 
of allocations (strating with 4). Is this still a good strategy with D 
having a GC?

..
switch( depth )
{

case 0:
if( temp.length < index[depth] ) temp.length = temp.length * 2;
break;

static if( is(U A:A[]))
{
case 1:
if( temp[ index[0] ].length < index[depth] ) temp[index[0]].length = 
temp[index[0]].length * 2;
break;
}

static if( is(U A:A[][]))
{
case 2:
if( temp[ index[0] ][ index[1] ].length < index[depth] ) temp[ index[0] ][ 
index[1] ].length = temp[ index[0] ][ index[1] ].length * 2;
break;
}

default:
assert(false);
break;
}
.. 




More information about the Digitalmars-d-learn mailing list