refactor(IO): clean up ffAppendFDBuffer

for 2 reasons:

- Simplify the Code.
- ffAppendFDBuffer can't make assumptions about how the read data will
  be processed, so the trim calls are inappropriate.
This commit is contained in:
apocelipes
2023-12-22 16:04:56 +09:00
committed by Carter Li
parent b7935aa238
commit e85a4b9ff5
3 changed files with 64 additions and 56 deletions
+2 -1
View File
@@ -54,6 +54,7 @@ void ffStrbufEnsureFree(FFstrbuf* strbuf, uint32_t free)
strbuf->allocated = allocate;
}
// for an empty buffer, free + 1 length memory will be allocated(+1 for the NUL)
void ffStrbufEnsureFixedLengthFree(FFstrbuf* strbuf, uint32_t free)
{
uint32_t oldFree = ffStrbufGetFree(strbuf);
@@ -64,7 +65,7 @@ void ffStrbufEnsureFixedLengthFree(FFstrbuf* strbuf, uint32_t free)
if(strbuf->allocated == 0)
{
newCap += strbuf->length + 1; // +1 for the NUL
newCap += strbuf->length + 1;
char* newbuf = malloc(sizeof(*strbuf->chars) * newCap);
if(strbuf->length == 0)
*newbuf = '\0';