Menu

#3 overhead by looping two times each line

open
nobody
None
5
2002-02-27
2002-02-27
Anonymous
No

In the function get_line() the whole line is looped to
replace all characters lower then ' ' with a ' '.
In expand_string again the whole line is looped. To
save execution time its better to move the replacement
from characters below ' ' to
expand_string, inside the loop to expand the string.
In that case the name expand_string doesn't exactly
match the functionality anymore but that's not a
problem I think.
So expand_string should do following (">new" indicates
the changes) :

while (ii < strlen(tempstr))
{
if ( tempstr[ii] == BACKSLASH )
{
......
......
}
else
{
>new if (tempstr[ii] < ' ')
>new {
>new tempstr[ii]= ' ';
>new }
newstr[jj] = tempstr[ii];
ii += 1;
jj += 1;
}

remove following code from get_line() :

i = 0;
while ((*lineptr != '\n') && ( i < MAX_LINE))
{
if (*lineptr < ' ')
{
*lineptr = ' ';
}
lineptr++;
i += 1;
}
} /* end of getline */

Discussion


Log in to post a comment.