1
0
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:
uz 2010-05-29 21:23:34 +00:00
parent 314893619a
commit b942fd0b56

View File

@ -179,7 +179,7 @@ static void SB_CheapRealloc (StrBuf* B, unsigned NewSize)
/* Allocate a fresh block */
B->Buf = xmalloc (NewAllocated);
/* Remember the new block size */
B->Allocated = NewAllocated;
}
@ -225,11 +225,13 @@ void SB_Terminate (StrBuf* B)
void SB_CopyBuf (StrBuf* Target, const char* Buf, unsigned Size)
/* Copy Buf to Target, discarding the old contents of Target */
{
if (Target->Allocated < Size) {
SB_CheapRealloc (Target, Size);
{
if (Size) {
if (Target->Allocated < Size) {
SB_CheapRealloc (Target, Size);
}
memcpy (Target->Buf, Buf, Size);
}
memcpy (Target->Buf, Buf, Size);
Target->Len = Size;
}