mirror of
https://github.com/yrutschle/sslh.git
synced 2025-04-12 15:17:14 +03:00
allow gap set and get to be inlined
This commit is contained in:
parent
f6fe735171
commit
82aeedefcd
2
Makefile
2
Makefile
@ -29,7 +29,7 @@ ifneq ($(strip $(COV_TEST)),)
|
||||
endif
|
||||
|
||||
CC ?= gcc
|
||||
CFLAGS ?=-Wall -DLIBPCRE -g $(CFLAGS_COV) $(CFLAGS_SAN)
|
||||
CFLAGS ?=-Wall -O2 -DLIBPCRE -g $(CFLAGS_COV) $(CFLAGS_SAN)
|
||||
|
||||
LIBS=-lm -lpcre2-8
|
||||
OBJS=sslh-conf.o common.o log.o sslh-main.o probe.o tls.o argtable3.o collection.o gap.o tcp-probe.o
|
||||
|
23
gap.c
23
gap.c
@ -31,11 +31,6 @@
|
||||
#include "gap.h"
|
||||
|
||||
|
||||
typedef struct gap_array {
|
||||
int len; /* Number of elements in array */
|
||||
void** array;
|
||||
} gap_array;
|
||||
|
||||
/* Allocate one page-worth of elements */
|
||||
static int gap_len_alloc(int elem_size)
|
||||
{
|
||||
@ -61,12 +56,7 @@ gap_array* gap_init(int len)
|
||||
return gap;
|
||||
}
|
||||
|
||||
void* gap_get(gap_array* gap, int index)
|
||||
{
|
||||
return gap->array[index];
|
||||
}
|
||||
|
||||
static int gap_extend(gap_array* gap)
|
||||
int gap_extend(gap_array* gap)
|
||||
{
|
||||
int elem_size = sizeof(gap->array[0]);
|
||||
int new_length = gap->len + gap_len_alloc(elem_size);
|
||||
@ -84,17 +74,6 @@ static int gap_extend(gap_array* gap)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gap_set(gap_array* gap, int index, void* ptr)
|
||||
{
|
||||
while (index >= gap->len) {
|
||||
int res = gap_extend(gap);
|
||||
if (res == -1) return -1;
|
||||
}
|
||||
|
||||
gap->array[index] = ptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void gap_destroy(gap_array* gap)
|
||||
{
|
||||
free(gap->array);
|
||||
|
29
gap.h
29
gap.h
@ -4,10 +4,35 @@
|
||||
typedef struct gap_array gap_array;
|
||||
|
||||
gap_array* gap_init(int len);
|
||||
void* gap_get(gap_array* gap, int index);
|
||||
int gap_set(gap_array* gap, int index, void* ptr);
|
||||
static void* gap_get(gap_array* gap, int index);
|
||||
static int gap_set(gap_array* gap, int index, void* ptr);
|
||||
void gap_destroy(gap_array* gap);
|
||||
|
||||
int gap_remove_ptr(gap_array* gap, void* ptr, int len);
|
||||
|
||||
/* Private declarations to allow inlining.
|
||||
* Don't assume my implementation. */
|
||||
typedef struct gap_array {
|
||||
int len; /* Number of elements in array */
|
||||
void** array;
|
||||
} gap_array;
|
||||
|
||||
int gap_extend(gap_array* gap);
|
||||
|
||||
static inline int __attribute__((unused)) gap_set(gap_array* gap, int index, void* ptr)
|
||||
{
|
||||
while (index >= gap->len) {
|
||||
int res = gap_extend(gap);
|
||||
if (res == -1) return -1;
|
||||
}
|
||||
|
||||
gap->array[index] = ptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void* __attribute__((unused)) gap_get(gap_array* gap, int index)
|
||||
{
|
||||
return gap->array[index];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user