Buffer: use inlines rather than #defines for the rest.
Might as well.
This commit is contained in:
parent
b8a94353b4
commit
5b39d79250
@ -130,7 +130,7 @@ ws_buffer_remove_start(Buffer* buffer, size_t bytes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef SOME_FUNCTIONS_ARE_DEFINES
|
#ifndef SOME_FUNCTIONS_ARE_INLINE
|
||||||
void
|
void
|
||||||
ws_buffer_clean(Buffer* buffer)
|
ws_buffer_clean(Buffer* buffer)
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#define SOME_FUNCTIONS_ARE_DEFINES
|
#define SOME_FUNCTIONS_ARE_INLINE
|
||||||
|
|
||||||
typedef struct Buffer {
|
typedef struct Buffer {
|
||||||
uint8_t *data;
|
uint8_t *data;
|
||||||
@ -39,7 +39,7 @@ void ws_buffer_remove_start(Buffer* buffer, size_t bytes);
|
|||||||
WS_DLL_PUBLIC
|
WS_DLL_PUBLIC
|
||||||
void ws_buffer_cleanup(void);
|
void ws_buffer_cleanup(void);
|
||||||
|
|
||||||
#ifdef SOME_FUNCTIONS_ARE_DEFINES
|
#ifdef SOME_FUNCTIONS_ARE_INLINE
|
||||||
/* Or inlines */
|
/* Or inlines */
|
||||||
static inline void
|
static inline void
|
||||||
ws_buffer_clean(Buffer *buffer)
|
ws_buffer_clean(Buffer *buffer)
|
||||||
@ -47,11 +47,36 @@ ws_buffer_clean(Buffer *buffer)
|
|||||||
buffer->start = 0;
|
buffer->start = 0;
|
||||||
buffer->first_free = 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)
|
static inline void
|
||||||
# define ws_buffer_start_ptr(buffer) ((buffer)->data + (buffer)->start)
|
ws_buffer_increase_length(Buffer* buffer, size_t bytes)
|
||||||
# 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))
|
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
|
#else
|
||||||
WS_DLL_PUBLIC
|
WS_DLL_PUBLIC
|
||||||
void ws_buffer_clean(Buffer* buffer);
|
void ws_buffer_clean(Buffer* buffer);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user