small optimizations

This commit is contained in:
hippoz 2023-01-16 04:10:21 +02:00
parent 41d0b1a8e5
commit 5e4a6dcf34
Signed by: hippoz
GPG key ID: 56C4E02A85F2FBED
3 changed files with 10 additions and 15 deletions

View file

@ -1,11 +1,11 @@
CC?=gcc
CFLAGS_DEV=-DJB_PRESET_DEBUG -ggdb -fsanitize=address -Og
CFLAGS_RELEASE=-O2 -ggdb
CFLAGS_RELEASE=-O3 -march=native -mtune=native -fgraphite-identity -flto
CFLAGS+=-pipe -Wall -Wextra -Wshadow -pedantic -std=c99
CFLAGS+=$(CFLAGS_RELEASE)
CFLAGS+=$(CFLAGS_DEV)
jitterbug: util.c wire.c match.c server.c main.c
$(CC) $(CFLAGS) -o $@ $^

View file

@ -696,7 +696,6 @@ int bus_client_process_message(bus_t *s, int i, wire_context_t *ctx)
wire_message_field_t *member_field = &msg.fields[DBUS_HEADER_FIELD_MEMBER];
uint8_t reply_data[8192];
memset(reply_data, 0, 8192);
wire_context_t reply_ctx = {
.byte_cursor = 0,
.data = reply_data,

20
wire.h
View file

@ -73,24 +73,20 @@ typedef struct wire_message_body_string {
M_type *wire_set_##M_mnemonic(wire_context_t *c, M_type val); \
#define _WIRE_DEF_BYTE_TYPE(M_mnemonic, M_type) \
M_type *wire_get_##M_mnemonic(wire_context_t *c) { \
uint32_t new_cursor = c->byte_cursor + 1; \
if (new_cursor >= c->data_len) return NULL; \
M_type *value = (M_type*)&c->data[c->byte_cursor]; \
c->byte_cursor = new_cursor; \
M_type *wire_get_##M_mnemonic(wire_context_t *restrict c) { \
if (c->byte_cursor + 1 >= c->data_len) return NULL; \
M_type *value = (M_type*)&c->data[c->byte_cursor++]; \
return value; \
} \
M_type *wire_set_##M_mnemonic(wire_context_t *c, M_type val) { \
uint32_t new_cursor = c->byte_cursor + 1; \
if (new_cursor >= c->data_len) return NULL; \
M_type *dest = (M_type*)&c->data[c->byte_cursor]; \
M_type *wire_set_##M_mnemonic(wire_context_t *restrict c, M_type val) { \
if (c->byte_cursor + 1 >= c->data_len) return NULL; \
M_type *dest = (M_type*)&c->data[c->byte_cursor++]; \
*dest = val; \
c->byte_cursor = new_cursor; \
return dest; \
} \
#define _WIRE_DEF_TYPE(M_mnemonic, M_type, M_alignment) \
M_type *wire_get_##M_mnemonic(wire_context_t *c) { \
M_type *wire_get_##M_mnemonic(wire_context_t *restrict c) { \
if (!wire_align(c, M_alignment)) return NULL; \
uint32_t new_cursor = c->byte_cursor + sizeof(M_type); \
if (new_cursor >= c->data_len) return NULL; \
@ -98,7 +94,7 @@ typedef struct wire_message_body_string {
c->byte_cursor = new_cursor; \
return value; \
} \
M_type *wire_set_##M_mnemonic(wire_context_t *c, M_type val) { \
M_type *wire_set_##M_mnemonic(wire_context_t *restrict c, M_type val) { \
if (!wire_write_align(c, M_alignment)) return NULL; \
uint32_t new_cursor = c->byte_cursor + sizeof(M_type); \
if (new_cursor >= c->data_len) return NULL; \