From 26325edb22082482f02a1a0fdb77692c4d7f5cb9 Mon Sep 17 00:00:00 2001 From: carlo-bramini <30959007+carlo-bramini@users.noreply.github.com> Date: Sun, 25 Nov 2018 21:13:25 +0100 Subject: [PATCH] Optimize device search Search of the MIDI device can be done before allocating the struct for the driver. --- src/drivers/fluid_winmidi.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/drivers/fluid_winmidi.c b/src/drivers/fluid_winmidi.c index ab630639..68b18f37 100644 --- a/src/drivers/fluid_winmidi.c +++ b/src/drivers/fluid_winmidi.c @@ -224,24 +224,11 @@ new_fluid_winmidi_driver(fluid_settings_t *settings, return NULL; } - dev = FLUID_MALLOC(sizeof(fluid_winmidi_driver_t)); - - if(dev == NULL) - { - return NULL; - } - - FLUID_MEMSET(dev, 0, sizeof(fluid_winmidi_driver_t)); - - dev->hmidiin = NULL; - dev->driver.handler = handler; - dev->driver.data = data; - /* get the device name. if none is specified, use the default device. */ if(fluid_settings_copystr(settings, "midi.winmidi.device", dev_name, MAXPNAMELEN) != FLUID_OK) { FLUID_LOG(FLUID_ERR, "Error getting MIDI device name"); - goto error_recovery; + return NULL; } /* check if there any midi devices installed */ @@ -250,7 +237,7 @@ new_fluid_winmidi_driver(fluid_settings_t *settings, if(num == 0) { FLUID_LOG(FLUID_ERR, "no MIDI in devices found"); - goto error_recovery; + return NULL; } /* find the device */ @@ -276,10 +263,23 @@ new_fluid_winmidi_driver(fluid_settings_t *settings, if(midi_num != i) { FLUID_LOG(FLUID_ERR, "Device <%s> does not exists", dev_name); - goto error_recovery; + return NULL; } } + dev = FLUID_MALLOC(sizeof(fluid_winmidi_driver_t)); + + if(dev == NULL) + { + return NULL; + } + + FLUID_MEMSET(dev, 0, sizeof(fluid_winmidi_driver_t)); + + dev->hmidiin = NULL; + dev->driver.handler = handler; + dev->driver.data = data; + /* try opening the device */ res = midiInOpen(&dev->hmidiin, midi_num, (DWORD_PTR) fluid_winmidi_callback,