From 5a15dc4ddf40ef547f7a776454488490c97f8d7f Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 14 Jun 2011 07:04:08 -0700 Subject: [PATCH] Avoid multiple list searches when destroying devices and contexts --- Alc/ALc.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Alc/ALc.c b/Alc/ALc.c index d704a98f..b56536c8 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -1612,17 +1612,17 @@ ALC_API ALCboolean ALC_APIENTRY alcCaptureCloseDevice(ALCdevice *pDevice) ALCdevice **list; LockLists(); - if(!IsDevice(pDevice) || !pDevice->IsCaptureDevice) + list = &g_pDeviceList; + while(*list && *list != pDevice) + list = &(*list)->next; + + if(!*list || !(*list)->IsCaptureDevice) { - alcSetError(pDevice, ALC_INVALID_DEVICE); + alcSetError(*list, ALC_INVALID_DEVICE); UnlockLists(); return ALC_FALSE; } - list = &g_pDeviceList; - while(*list != pDevice) - list = &(*list)->next; - *list = (*list)->next; g_ulDeviceCount--; @@ -2187,17 +2187,17 @@ ALC_API ALCvoid ALC_APIENTRY alcDestroyContext(ALCcontext *context) ALuint i; LockLists(); - if(!IsContext(context)) + list = &g_pContextList; + while(*list && *list != context) + list = &(*list)->next; + + if(!*list) { alcSetError(NULL, ALC_INVALID_CONTEXT); UnlockLists(); return; } - list = &g_pContextList; - while(*list != context) - list = &(*list)->next; - *list = (*list)->next; g_ulContextCount--; @@ -2693,17 +2693,17 @@ ALC_API ALCboolean ALC_APIENTRY alcCloseDevice(ALCdevice *pDevice) ALCdevice **list; LockLists(); - if(!IsDevice(pDevice) || pDevice->IsCaptureDevice) + list = &g_pDeviceList; + while(*list && *list != pDevice) + list = &(*list)->next; + + if(!*list || (*list)->IsCaptureDevice) { - alcSetError(pDevice, ALC_INVALID_DEVICE); + alcSetError(*list, ALC_INVALID_DEVICE); UnlockLists(); return ALC_FALSE; } - list = &g_pDeviceList; - while(*list != pDevice) - list = &(*list)->next; - *list = (*list)->next; g_ulDeviceCount--;