Skip to content

Commit

Permalink
allow gap set and get to be inlined
Browse files Browse the repository at this point in the history
  • Loading branch information
yrutschle committed May 5, 2022
1 parent f6fe735 commit 82aeede
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 1 addition & 22 deletions gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand All @@ -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);
Expand Down
29 changes: 27 additions & 2 deletions gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 82aeede

Please sign in to comment.