Skip to content

Commit 22a8cfd

Browse files
Remove obsolete strbuf function
1 parent 63041aa commit 22a8cfd

File tree

3 files changed

+11
-31
lines changed

3 files changed

+11
-31
lines changed

src/common/io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void ffAppendFDContent(int fd, FFstrbuf* buffer)
6161
(uint32_t) readed == free
6262
) {
6363
buffer->length += (uint32_t) readed;
64-
ffStrbufEnsureCapacity(buffer, (buffer->allocated * 2) - 1); // -1 for null terminator
64+
ffStrbufEnsureFree(buffer, buffer->allocated - 1); // Doubles capacity every round. -1 for the null byte.
6565
free = ffStrbufGetFree(buffer);
6666
}
6767

src/util/FFstrbuf.c

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,12 @@ void ffStrbufInitCopy(FFstrbuf* strbuf, const FFstrbuf* src)
2929
ffStrbufAppend(strbuf, src);
3030
}
3131

32-
static void setCapacity(FFstrbuf* strbuf, uint32_t capacity)
32+
uint32_t ffStrbufGetFree(const FFstrbuf* strbuf)
3333
{
3434
if(strbuf->allocated == 0)
35-
{
36-
strbuf->chars = malloc(sizeof(*strbuf->chars) * capacity);
37-
strbuf->chars[0] = '\0';
38-
}
39-
else
40-
strbuf->chars = realloc(strbuf->chars, sizeof(*strbuf->chars) * capacity);
41-
42-
strbuf->allocated = capacity;
43-
}
44-
45-
void ffStrbufEnsureCapacity(FFstrbuf* strbuf, uint32_t capacity)
46-
{
47-
if(strbuf->allocated > capacity || capacity == 0)
48-
return;
49-
50-
if(capacity == UINT32_MAX)
51-
{
52-
fputs("Warning: ffStrbufEnsureCapacity called with UINT32_MAX. Highest allowed value is UINT32_MAX - 1. Exiting.\n", stderr);
53-
exit(812);
54-
}
35+
return 0;
5536

56-
setCapacity(strbuf, capacity + 1); // + 1 for the null byte
37+
return strbuf->allocated - strbuf->length - 1; // - 1 for the null byte
5738
}
5839

5940
void ffStrbufEnsureFree(FFstrbuf* strbuf, uint32_t free)
@@ -68,15 +49,15 @@ void ffStrbufEnsureFree(FFstrbuf* strbuf, uint32_t free)
6849
while((strbuf->length + free + 1) > allocate) // + 1 for the null byte
6950
allocate *= 2;
7051

71-
setCapacity(strbuf, allocate);
72-
}
73-
74-
uint32_t ffStrbufGetFree(const FFstrbuf* strbuf)
75-
{
7652
if(strbuf->allocated == 0)
77-
return 0;
53+
{
54+
strbuf->chars = malloc(sizeof(*strbuf->chars) * allocate);
55+
strbuf->chars[0] = '\0';
56+
}
57+
else
58+
strbuf->chars = realloc(strbuf->chars, sizeof(*strbuf->chars) * allocate);
7859

79-
return strbuf->allocated - strbuf->length - 1; // - 1 for the null byte
60+
strbuf->allocated = allocate;
8061
}
8162

8263
void ffStrbufClear(FFstrbuf* strbuf)

src/util/FFstrbuf.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ void ffStrbufInit(FFstrbuf* strbuf);
2323
void ffStrbufInitA(FFstrbuf* strbuf, uint32_t allocate);
2424
void ffStrbufInitCopy(FFstrbuf* strbuf, const FFstrbuf* src);
2525

26-
void ffStrbufEnsureCapacity(FFstrbuf* strbuf, uint32_t capacity);
2726
void ffStrbufEnsureFree(FFstrbuf* strbuf, uint32_t free);
2827

2928
uint32_t ffStrbufGetFree(const FFstrbuf* strbuf);

0 commit comments

Comments
 (0)