From 5f6531ef7edfef8b2056f5a6010603f00f210475 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 15 Nov 2024 21:11:56 -0500 Subject: Remove redundant condition Reduce nesting in the implementation by ensuring that state is non-null at the caller. --- src/state.c | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) (limited to 'src/state.c') diff --git a/src/state.c b/src/state.c index 1d473eb..27be61c 100644 --- a/src/state.c +++ b/src/state.c @@ -171,30 +171,30 @@ set_port_value(const char* port_symbol, void jalv_apply_state(Jalv* jalv, const LilvState* state) { - bool must_pause = !jalv->safe_restore && jalv->play_state == JALV_RUNNING; - if (state) { - if (must_pause) { - jalv->play_state = JALV_PAUSE_REQUESTED; - zix_sem_wait(&jalv->paused); - } + const bool must_pause = + !jalv->safe_restore && jalv->play_state == JALV_RUNNING; + if (must_pause) { + jalv->play_state = JALV_PAUSE_REQUESTED; + zix_sem_wait(&jalv->paused); + } - const LV2_Feature* state_features[9] = { - &jalv->features.map_feature, - &jalv->features.unmap_feature, - &jalv->features.make_path_feature, - &jalv->features.state_sched_feature, - &jalv->features.safe_restore_feature, - &jalv->features.log_feature, - &jalv->features.options_feature, - NULL}; - - lilv_state_restore( - state, jalv->instance, set_port_value, jalv, 0, state_features); - - if (must_pause) { - jalv->request_update = true; - jalv->play_state = JALV_RUNNING; - } + const LV2_Feature* state_features[9] = { + &jalv->features.map_feature, + &jalv->features.unmap_feature, + &jalv->features.make_path_feature, + &jalv->features.state_sched_feature, + &jalv->features.safe_restore_feature, + &jalv->features.log_feature, + &jalv->features.options_feature, + NULL, + }; + + lilv_state_restore( + state, jalv->instance, set_port_value, jalv, 0, state_features); + + if (must_pause) { + jalv->request_update = true; + jalv->play_state = JALV_RUNNING; } } @@ -203,7 +203,9 @@ jalv_apply_preset(Jalv* jalv, const LilvNode* preset) { lilv_state_free(jalv->preset); jalv->preset = lilv_state_new_from_world(jalv->world, &jalv->map, preset); - jalv_apply_state(jalv, jalv->preset); + if (jalv->preset) { + jalv_apply_state(jalv, jalv->preset); + } return 0; } -- cgit v1.2.1