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