From 6dcb3b662edef226933f33d1fcea26403861672b Mon Sep 17 00:00:00 2001 From: cuz Date: Sat, 14 Jul 2001 15:55:52 +0000 Subject: [PATCH] Avoid a copy of the line contents git-svn-id: svn://svn.cc65.org/cc65/trunk@786 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/lineinfo.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/cc65/lineinfo.c b/src/cc65/lineinfo.c index 60ba962ef..342eeaced 100644 --- a/src/cc65/lineinfo.c +++ b/src/cc65/lineinfo.c @@ -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; } -- 2.39.5