Skip to content

Commit

Permalink
perf(vec): make functions static inline
Browse files Browse the repository at this point in the history
  • Loading branch information
mkroening committed Jan 21, 2025
1 parent 6a5c9ec commit 45bfb6d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
size_t len; \
}; \
\
struct name name##_new(void) { \
/* NOLINTNEXTLINE(clang-diagnostic-unused-function) */ \
static inline struct name name##_new(void) { \
struct name v = { \
.ptr = NULL, \
.cap = 0, \
Expand All @@ -19,7 +20,8 @@
return v; \
} \
\
void name##_grow_one(struct name *v) { \
/* NOLINTNEXTLINE(clang-diagnostic-unused-function) */ \
static inline void name##_grow_one(struct name *v) { \
if (v->cap == 0) { \
v->cap = 1; \
} else { \
Expand All @@ -31,7 +33,8 @@
v->ptr = ptr; \
} \
\
void name##_push(struct name *v, ty value) { \
/* NOLINTNEXTLINE(clang-diagnostic-unused-function) */ \
static inline void name##_push(struct name *v, ty value) { \
if (v->len == v->cap) { \
name##_grow_one(v); \
} \
Expand All @@ -40,14 +43,16 @@
v->len += 1; \
} \
\
ty name##_pop(struct name *v) { \
/* NOLINTNEXTLINE(clang-diagnostic-unused-function) */ \
static inline ty name##_pop(struct name *v) { \
assert(v->len != 0); \
\
v->len -= 1; \
return *(v->ptr + v->len); \
} \
\
ty name##_swap_remove(struct name *v, size_t index) { \
/* NOLINTNEXTLINE(clang-diagnostic-unused-function) */ \
static inline ty name##_swap_remove(struct name *v, size_t index) { \
assert(index < v->len); \
\
ty value = *(v->ptr + index); \
Expand All @@ -58,7 +63,8 @@
return value; \
} \
\
void name##_drop(struct name *v) { \
/* NOLINTNEXTLINE(clang-diagnostic-unused-function) */ \
static inline void name##_drop(struct name *v) { \
free(v->ptr); \
*v = name##_new(); \
}

0 comments on commit 45bfb6d

Please sign in to comment.