Buffer: use inlines rather than #defines for the rest.

Might as well.
This commit is contained in:
Guy Harris 2025-01-01 19:35:17 -08:00
parent b8a94353b4
commit 5b39d79250
2 changed files with 33 additions and 8 deletions

View File

@ -130,7 +130,7 @@ ws_buffer_remove_start(Buffer* buffer, size_t bytes)
}
#ifndef SOME_FUNCTIONS_ARE_DEFINES
#ifndef SOME_FUNCTIONS_ARE_INLINE
void
ws_buffer_clean(Buffer* buffer)
{

View File

@ -17,7 +17,7 @@
extern "C" {
#endif /* __cplusplus */
#define SOME_FUNCTIONS_ARE_DEFINES
#define SOME_FUNCTIONS_ARE_INLINE
typedef struct Buffer {
uint8_t *data;
@ -39,7 +39,7 @@ void ws_buffer_remove_start(Buffer* buffer, size_t bytes);
WS_DLL_PUBLIC
void ws_buffer_cleanup(void);
#ifdef SOME_FUNCTIONS_ARE_DEFINES
#ifdef SOME_FUNCTIONS_ARE_INLINE
/* Or inlines */
static inline void
ws_buffer_clean(Buffer *buffer)
@ -47,11 +47,36 @@ ws_buffer_clean(Buffer *buffer)
buffer->start = 0;
buffer->first_free = 0;
}
# define ws_buffer_increase_length(buffer,bytes) (buffer)->first_free += (bytes)
# define ws_buffer_length(buffer) ((buffer)->first_free - (buffer)->start)
# define ws_buffer_start_ptr(buffer) ((buffer)->data + (buffer)->start)
# define ws_buffer_end_ptr(buffer) ((buffer)->data + (buffer)->first_free)
# define ws_buffer_append_buffer(buffer,src_buffer) ws_buffer_append((buffer), ws_buffer_start_ptr(src_buffer), ws_buffer_length(src_buffer))
static inline void
ws_buffer_increase_length(Buffer* buffer, size_t bytes)
{
buffer->first_free += bytes;
}
static inline size_t
ws_buffer_length(Buffer* buffer)
{
return buffer->first_free - buffer->start;
}
static inline uint8_t *
ws_buffer_start_ptr(Buffer* buffer)
{
return buffer->data + buffer->start;
}
static inline uint8_t *
ws_buffer_end_ptr(Buffer* buffer)
{
return buffer->data + buffer->first_free;
}
static inline void
ws_buffer_append_buffer(Buffer* buffer, Buffer* src_buffer)
{
ws_buffer_append(buffer, ws_buffer_start_ptr(src_buffer), ws_buffer_length(src_buffer));
}
#else
WS_DLL_PUBLIC
void ws_buffer_clean(Buffer* buffer);