I have a program where I am filling some string values.
In my first, quick, attempt, I repeated some code
three times that performed this function three times.
So I decided to create a routine that I could call
three times rather than having the code repeated. Everything
that is in the new routine was cut-and-pasted from what
was repeated. No new code.
My question is: Why did my program grow when I used
the single routine rather than the repeated code? It
seems like the version that had the repeated code would
be larger.
Below is the structure of the new code. The original code
had the contents of SetStringVal repeated in the routine
following SetStringVal.
SetStringVal(char * str, char * strVal)
{
// This code was repeated three times in the routine below
}
// where d1, p2, p1 are char *.
static void FillDB()
{
UInt i, j, k;
curIdx=0;
for(i=0; i < 10; i++)
{
for(j=0; j < 10; j++)
{
for(k=0; k < 10; k++)
{
SetStringValue(d1, &k); // code above replaced by call
SetStringValue(p2, &j); //
SetStringValue(p1, &i); //
}
}
}
}