From 5e4a6dcf3480221b74581cf176c26549f49f5723 Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Mon, 16 Jan 2023 04:10:21 +0200 Subject: [PATCH] small optimizations --- Makefile | 4 ++-- server.c | 1 - wire.h | 20 ++++++++------------ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 04614de..e78c0fa 100644 --- a/Makefile +++ b/Makefile @@ -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 $@ $^ diff --git a/server.c b/server.c index f0f9c6c..9cd1bf5 100644 --- a/server.c +++ b/server.c @@ -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, diff --git a/wire.h b/wire.h index 59c9edd..0495d34 100644 --- a/wire.h +++ b/wire.h @@ -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; \