1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-10 19:29:45 +00:00

Avoid a copy of the line contents

git-svn-id: svn://svn.cc65.org/cc65/trunk@786 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2001-07-14 15:55:52 +00:00
parent 02b81bdd69
commit 6dcb3b662e

View File

@ -69,7 +69,7 @@ static LineInfo* NewLineInfo (struct IFile* F, unsigned LineNum, const char* Lin
{
unsigned Len;
LineInfo* LI;
char* S;
char* T;
/* Skip leading spaces in Line */
while (IsBlank (*Line)) {
@ -86,20 +86,25 @@ static LineInfo* NewLineInfo (struct IFile* F, unsigned LineNum, const char* Lin
LI->RefCount = 1;
LI->InputFile = F;
LI->LineNum = LineNum;
memcpy (LI->Line, Line, Len+1);
/* Replace tabs by spaces in the given line since tabs will give rather
* arbitrary results when used in the output later, and if we do it here,
* we won't need another copy.
/* Copy the line, replacing tabs by spaces in the given line since tabs
* will give rather arbitrary results when used in the output later, and
* if we do it here, we won't need another copy later.
*/
S = LI->Line;
while (*S) {
if (*S == '\t') {
*S = ' ';
T = LI->Line;
while (Len--) {
if (*Line == '\t') {
*T = ' ';
} else {
*T = *Line;
}
++S;
++Line;
++T;
}
/* Add the terminator */
*T = '\0';
/* Return the new struct */
return LI;
}