mirror of
https://github.com/cc65/cc65.git
synced 2025-01-13 09:31:53 +00:00
Check for a size of zero in SB_CopyBuf to make the code somewhat faster.
git-svn-id: svn://svn.cc65.org/cc65/trunk@4675 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
314893619a
commit
b942fd0b56
@ -179,7 +179,7 @@ static void SB_CheapRealloc (StrBuf* B, unsigned NewSize)
|
|||||||
|
|
||||||
/* Allocate a fresh block */
|
/* Allocate a fresh block */
|
||||||
B->Buf = xmalloc (NewAllocated);
|
B->Buf = xmalloc (NewAllocated);
|
||||||
|
|
||||||
/* Remember the new block size */
|
/* Remember the new block size */
|
||||||
B->Allocated = NewAllocated;
|
B->Allocated = NewAllocated;
|
||||||
}
|
}
|
||||||
@ -225,11 +225,13 @@ void SB_Terminate (StrBuf* B)
|
|||||||
|
|
||||||
void SB_CopyBuf (StrBuf* Target, const char* Buf, unsigned Size)
|
void SB_CopyBuf (StrBuf* Target, const char* Buf, unsigned Size)
|
||||||
/* Copy Buf to Target, discarding the old contents of Target */
|
/* Copy Buf to Target, discarding the old contents of Target */
|
||||||
{
|
{
|
||||||
if (Target->Allocated < Size) {
|
if (Size) {
|
||||||
SB_CheapRealloc (Target, Size);
|
if (Target->Allocated < Size) {
|
||||||
|
SB_CheapRealloc (Target, Size);
|
||||||
|
}
|
||||||
|
memcpy (Target->Buf, Buf, Size);
|
||||||
}
|
}
|
||||||
memcpy (Target->Buf, Buf, Size);
|
|
||||||
Target->Len = Size;
|
Target->Len = Size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user