diff --git a/src/emu/chan.c b/src/emu/chan.c index 1c1f8c7..44faf0c 100644 --- a/src/emu/chan.c +++ b/src/emu/chan.c @@ -204,7 +204,7 @@ chan_pop(struct chan *chan, struct value evalue) static void get_value(struct chan *chan, struct value *value) { - if (chan->type == CHAN_SINGLE) { + if (likely(chan->type == CHAN_SINGLE)) { *value = chan->data.value; } else { struct chan_stack *stack = &chan->data.stack; @@ -215,15 +215,6 @@ get_value(struct chan *chan, struct value *value) } } -/** Reads the current value of a channel */ -int -chan_read(struct chan *chan, struct value *value) -{ - get_value(chan, value); - - return 0; -} - /** Remove the dirty state */ int chan_flush(struct chan *chan) diff --git a/src/emu/chan.h b/src/emu/chan.h index 500fe60..908387f 100644 --- a/src/emu/chan.h +++ b/src/emu/chan.h @@ -53,11 +53,27 @@ struct chan { char name[MAX_CHAN_NAME]; }; +/** Reads the current value of a channel */ +USE_RET static inline int +chan_read(struct chan *chan, struct value *value) +{ + if (likely(chan->type == CHAN_SINGLE)) { + *value = chan->data.value; + } else { + struct chan_stack *stack = &chan->data.stack; + if (stack->n > 0) + *value = stack->values[stack->n - 1]; + else + *value = value_null(); + } + + return 0; +} + void chan_init(struct chan *chan, enum chan_type type, const char *fmt, ...); USE_RET int chan_set(struct chan *chan, struct value value); USE_RET int chan_push(struct chan *chan, struct value value); USE_RET int chan_pop(struct chan *chan, struct value expected); -USE_RET int chan_read(struct chan *chan, struct value *value); USE_RET enum chan_type chan_get_type(struct chan *chan); USE_RET int chan_flush(struct chan *chan); void chan_prop_set(struct chan *chan, enum chan_prop prop, int value);