aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-08-09 06:15:11 -0700
committerChris Robinson <[email protected]>2014-08-09 06:15:11 -0700
commitf173a6787082e577a6bb8de08577980118bcd029 (patch)
tree6f5ecb9fc8be131980274bf400a5f6ab1d8753bb /Alc
parent1692dda4b9908d97c80ec5e446f642b24374667b (diff)
Use VECTOR_FIND_IF and VECTOR_FOR_EACH instead of manual loops
Diffstat (limited to 'Alc')
-rw-r--r--Alc/alstring.h2
-rw-r--r--Alc/backends/alsa.c36
-rw-r--r--Alc/backends/dsound.c49
-rw-r--r--Alc/backends/pulseaudio.c76
4 files changed, 57 insertions, 106 deletions
diff --git a/Alc/alstring.h b/Alc/alstring.h
index d5f64418..32f4280a 100644
--- a/Alc/alstring.h
+++ b/Alc/alstring.h
@@ -13,7 +13,7 @@ inline void al_string_deinit(al_string *str)
{ VECTOR_DEINIT(*str); }
#define AL_STRING_INIT(_x) do { (_x) = (al_string)NULL; } while(0)
#define AL_STRING_INIT_STATIC() ((al_string)NULL)
-#define AL_STRING_DEINIT(_x) al_string_deinit(&(_x));
+#define AL_STRING_DEINIT(_x) al_string_deinit(&(_x))
inline ALsizei al_string_length(const_al_string str)
{ return VECTOR_SIZE(str); }
diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c
index 2d3a8425..d5174da8 100644
--- a/Alc/backends/alsa.c
+++ b/Alc/backends/alsa.c
@@ -625,23 +625,17 @@ static ALCenum ALCplaybackAlsa_open(ALCplaybackAlsa *self, const ALCchar *name)
if(name)
{
- const DevMap *iter, *end;
+ const DevMap *iter;
if(VECTOR_SIZE(PlaybackDevices) == 0)
probe_devices(SND_PCM_STREAM_PLAYBACK, &PlaybackDevices);
- iter = VECTOR_ITER_BEGIN(PlaybackDevices);
- end = VECTOR_ITER_END(PlaybackDevices);
- for(;iter != end;iter++)
- {
- if(al_string_cmp_cstr(iter->name, name) == 0)
- {
- driver = al_string_get_cstr(iter->device_name);
- break;
- }
- }
- if(iter == end)
+#define MATCH_NAME(i) (al_string_cmp_cstr((i)->name, name) == 0)
+ VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_NAME);
+#undef MATCH_NAME
+ if(iter == VECTOR_ITER_END(PlaybackDevices))
return ALC_INVALID_VALUE;
+ driver = al_string_get_cstr(iter->device_name);
}
else
{
@@ -956,23 +950,17 @@ static ALCenum ALCcaptureAlsa_open(ALCcaptureAlsa *self, const ALCchar *name)
if(name)
{
- const DevMap *iter, *end;
+ const DevMap *iter;
if(VECTOR_SIZE(CaptureDevices) == 0)
probe_devices(SND_PCM_STREAM_CAPTURE, &CaptureDevices);
- iter = VECTOR_ITER_BEGIN(CaptureDevices);
- end = VECTOR_ITER_END(CaptureDevices);
- for(;iter != end;iter++)
- {
- if(al_string_cmp_cstr(iter->name, name) == 0)
- {
- driver = al_string_get_cstr(iter->device_name);
- break;
- }
- }
- if(iter == end)
+#define MATCH_NAME(i) (al_string_cmp_cstr((i)->name, name) == 0)
+ VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_NAME);
+#undef MATCH_NAME
+ if(iter == VECTOR_ITER_END(CaptureDevices))
return ALC_INVALID_VALUE;
+ driver = al_string_get_cstr(iter->device_name);
}
else
{
diff --git a/Alc/backends/dsound.c b/Alc/backends/dsound.c
index f5dcfe59..2229347e 100644
--- a/Alc/backends/dsound.c
+++ b/Alc/backends/dsound.c
@@ -116,12 +116,9 @@ static vector_DevMap CaptureDevices;
static void clear_devlist(vector_DevMap *list)
{
- DevMap *iter, *end;
-
- iter = VECTOR_ITER_BEGIN(*list);
- end = VECTOR_ITER_END(*list);
- for(;iter != end;++iter)
- AL_STRING_DEINIT(iter->name);
+#define DEINIT_STR(i) AL_STRING_DEINIT((i)->name)
+ VECTOR_FOR_EACH(DevMap, *list, DEINIT_STR);
+#undef DEINIT_STR
VECTOR_RESIZE(*list, 0);
}
@@ -323,7 +320,7 @@ FORCE_ALIGN static int ALCdsoundPlayback_mixerProc(void *ptr)
static ALCenum ALCdsoundPlayback_open(ALCdsoundPlayback *self, const ALCchar *deviceName)
{
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
- GUID *guid = NULL;
+ const GUID *guid = NULL;
HRESULT hr, hrcom;
if(VECTOR_SIZE(PlaybackDevices) == 0)
@@ -344,20 +341,14 @@ static ALCenum ALCdsoundPlayback_open(ALCdsoundPlayback *self, const ALCchar *de
}
else
{
- DevMap *iter, *end;
+ const DevMap *iter;
- iter = VECTOR_ITER_BEGIN(PlaybackDevices);
- end = VECTOR_ITER_END(PlaybackDevices);
- for(;iter != end;++iter)
- {
- if(al_string_cmp_cstr(iter->name, deviceName) == 0)
- {
- guid = &iter->guid;
- break;
- }
- }
- if(iter == end)
+#define MATCH_NAME(i) (al_string_cmp_cstr((i)->name, deviceName) == 0)
+ VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_NAME);
+#undef MATCH_NAME
+ if(iter == VECTOR_ITER_END(PlaybackDevices))
return ALC_INVALID_VALUE;
+ guid = &iter->guid;
}
hr = DS_OK;
@@ -681,7 +672,7 @@ static ALCenum ALCdsoundCapture_open(ALCdsoundCapture *self, const ALCchar *devi
ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice;
WAVEFORMATEXTENSIBLE InputType;
DSCBUFFERDESC DSCBDescription;
- GUID *guid = NULL;
+ const GUID *guid = NULL;
HRESULT hr, hrcom;
ALuint samples;
@@ -703,20 +694,14 @@ static ALCenum ALCdsoundCapture_open(ALCdsoundCapture *self, const ALCchar *devi
}
else
{
- DevMap *iter, *end;
+ const DevMap *iter;
- iter = VECTOR_ITER_BEGIN(CaptureDevices);
- end = VECTOR_ITER_END(CaptureDevices);
- for(;iter != end;++iter)
- {
- if(al_string_cmp_cstr(iter->name, deviceName) == 0)
- {
- guid = &iter->guid;
- break;
- }
- }
- if(iter == end)
+#define MATCH_NAME(i) (al_string_cmp_cstr((i)->name, deviceName) == 0)
+ VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_NAME);
+#undef MATCH_NAME
+ if(iter == VECTOR_ITER_END(CaptureDevices))
return ALC_INVALID_VALUE;
+ guid = &iter->guid;
}
switch(device->FmtType)
diff --git a/Alc/backends/pulseaudio.c b/Alc/backends/pulseaudio.c
index 90166127..8bd731ff 100644
--- a/Alc/backends/pulseaudio.c
+++ b/Alc/backends/pulseaudio.c
@@ -467,15 +467,9 @@ static vector_DevMap CaptureDevices;
static void clear_devlist(vector_DevMap *list)
{
- DevMap *iter, *end;
-
- iter = VECTOR_ITER_BEGIN(*list);
- end = VECTOR_ITER_END(*list);
- for(;iter != end;iter++)
- {
- AL_STRING_DEINIT(iter->name);
- AL_STRING_DEINIT(iter->device_name);
- }
+#define DEINIT_STRS(i) (AL_STRING_DEINIT((i)->name),AL_STRING_DEINIT((i)->device_name))
+ VECTOR_FOR_EACH(DevMap, *list, DEINIT_STRS);
+#undef DEINIT_STRS
VECTOR_RESIZE(*list, 0);
}
@@ -548,7 +542,7 @@ static void ALCpulsePlayback_Destruct(ALCpulsePlayback *self)
static void ALCpulsePlayback_deviceCallback(pa_context *UNUSED(context), const pa_sink_info *info, int eol, void *pdata)
{
pa_threaded_mainloop *loop = pdata;
- const DevMap *iter, *end;
+ const DevMap *iter;
DevMap entry;
if(eol)
@@ -557,13 +551,11 @@ static void ALCpulsePlayback_deviceCallback(pa_context *UNUSED(context), const p
return;
}
- iter = VECTOR_ITER_BEGIN(PlaybackDevices);
- end = VECTOR_ITER_END(PlaybackDevices);
- for(;iter != end;iter++)
- {
- if(al_string_cmp_cstr(iter->device_name, info->name) == 0)
- return;
- }
+#define MATCH_INFO_NAME(iter) (al_string_cmp_cstr((iter)->device_name, info->name) == 0)
+ VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_INFO_NAME);
+#undef MATCH_INFO_NAME
+ if(iter != VECTOR_ITER_END(PlaybackDevices))
+ return;
TRACE("Got device \"%s\", \"%s\"\n", info->description, info->name);
@@ -856,23 +848,17 @@ static ALCenum ALCpulsePlayback_open(ALCpulsePlayback *self, const ALCchar *name
if(name)
{
- const DevMap *iter, *end;
+ const DevMap *iter;
if(VECTOR_SIZE(PlaybackDevices) == 0)
ALCpulsePlayback_probeDevices();
- iter = VECTOR_ITER_BEGIN(PlaybackDevices);
- end = VECTOR_ITER_END(PlaybackDevices);
- for(;iter != end;iter++)
- {
- if(al_string_cmp_cstr(iter->name, name) == 0)
- {
- pulse_name = al_string_get_cstr(iter->device_name);
- break;
- }
- }
- if(iter == end)
+#define MATCH_NAME(iter) (al_string_cmp_cstr((iter)->name, name) == 0)
+ VECTOR_FIND_IF(iter, const DevMap, PlaybackDevices, MATCH_NAME);
+#undef MATCH_NAME
+ if(iter == VECTOR_ITER_END(PlaybackDevices))
return ALC_INVALID_VALUE;
+ pulse_name = al_string_get_cstr(iter->device_name);
}
if(!pulse_open(&self->loop, &self->context, ALCpulsePlayback_contextStateCallback, self))
@@ -1211,7 +1197,7 @@ static void ALCpulseCapture_Destruct(ALCpulseCapture *self)
static void ALCpulseCapture_deviceCallback(pa_context *UNUSED(context), const pa_source_info *info, int eol, void *pdata)
{
pa_threaded_mainloop *loop = pdata;
- const DevMap *iter, *end;
+ const DevMap *iter;
DevMap entry;
if(eol)
@@ -1220,13 +1206,11 @@ static void ALCpulseCapture_deviceCallback(pa_context *UNUSED(context), const pa
return;
}
- iter = VECTOR_ITER_BEGIN(CaptureDevices);
- end = VECTOR_ITER_END(CaptureDevices);
- for(;iter != end;iter++)
- {
- if(al_string_cmp_cstr(iter->device_name, info->name) == 0)
- return;
- }
+#define MATCH_INFO_NAME(iter) (al_string_cmp_cstr((iter)->device_name, info->name) == 0)
+ VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_INFO_NAME);
+#undef MATCH_INFO_NAME
+ if(iter != VECTOR_ITER_END(CaptureDevices))
+ return;
TRACE("Got device \"%s\", \"%s\"\n", info->description, info->name);
@@ -1393,23 +1377,17 @@ static ALCenum ALCpulseCapture_open(ALCpulseCapture *self, const ALCchar *name)
if(name)
{
- const DevMap *iter, *end;
+ const DevMap *iter;
if(VECTOR_SIZE(CaptureDevices) == 0)
ALCpulseCapture_probeDevices();
- iter = VECTOR_ITER_BEGIN(CaptureDevices);
- end = VECTOR_ITER_END(CaptureDevices);
- for(;iter != end;iter++)
- {
- if(al_string_cmp_cstr(iter->name, name) == 0)
- {
- pulse_name = al_string_get_cstr(iter->device_name);
- break;
- }
- }
- if(iter == end)
+#define MATCH_NAME(iter) (al_string_cmp_cstr((iter)->name, name) == 0)
+ VECTOR_FIND_IF(iter, const DevMap, CaptureDevices, MATCH_NAME);
+#undef MATCH_NAME
+ if(iter == VECTOR_ITER_END(CaptureDevices))
return ALC_INVALID_VALUE;
+ pulse_name = al_string_get_cstr(iter->device_name);
}
if(!pulse_open(&self->loop, &self->context, ALCpulseCapture_contextStateCallback, self))