From: uz Date: Sat, 29 May 2010 21:23:34 +0000 (+0000) Subject: Check for a size of zero in SB_CopyBuf to make the code somewhat faster. X-Git-Tag: V2.13.3~754 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b942fd0b560868957dbee542200c235a737e6b5e;p=cc65 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 --- diff --git a/src/common/strbuf.c b/src/common/strbuf.c index 4a489a708..320e91293 100644 --- a/src/common/strbuf.c +++ b/src/common/strbuf.c @@ -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; }