clean up some more array iterations

This commit is contained in:
Wim Taymans 2022-09-30 17:23:05 +02:00
parent 0b98614bea
commit 9b6e504c19
14 changed files with 88 additions and 114 deletions

View file

@ -109,10 +109,9 @@ static const struct channelmix_upmix_info {
static inline uint32_t channelmix_upmix_from_label(const char *label)
{
uint32_t i;
for (i = 0; i < SPA_N_ELEMENTS(channelmix_upmix_info); i++) {
if (spa_streq(channelmix_upmix_info[i].label, label))
return channelmix_upmix_info[i].upmix;
SPA_FOR_EACH_ELEMENT_VAR(channelmix_upmix_info, i) {
if (spa_streq(i->label, label))
return i->upmix;
}
return CHANNELMIX_UPMIX_NONE;
}

View file

@ -88,10 +88,9 @@ static enum spa_bt_feature parse_feature(const char *str)
{ "faststream", SPA_BT_FEATURE_FASTSTREAM },
{ "a2dp-duplex", SPA_BT_FEATURE_A2DP_DUPLEX },
};
size_t i;
for (i = 0; i < SPA_N_ELEMENTS(feature_keys); ++i) {
if (spa_streq(str, feature_keys[i].key))
return feature_keys[i].value;
SPA_FOR_EACH_ELEMENT_VAR(feature_keys, f) {
if (spa_streq(str, f->key))
return f->value;
}
return 0;
}

View file

@ -171,19 +171,18 @@ impl_cpu_get_vm_type(void *object)
/* https://wiki.freebsd.org/bhyve */
{ "BHYVE", SPA_CPU_VM_BHYVE },
};
uint32_t i, j;
for (i = 0; i < SPA_N_ELEMENTS(dmi_vendors); i++) {
SPA_FOR_EACH_ELEMENT_VAR(dmi_vendors, dv) {
char buffer[256], *s;
if ((s = read_file(dmi_vendors[i], buffer, sizeof(buffer))) == NULL)
if ((s = read_file(*dv, buffer, sizeof(buffer))) == NULL)
continue;
for (j = 0; j < SPA_N_ELEMENTS(dmi_vendor_table); j++) {
if (spa_strstartswith(s, dmi_vendor_table[j].vendor)) {
SPA_FOR_EACH_ELEMENT_VAR(dmi_vendor_table, t) {
if (spa_strstartswith(s, t->vendor)) {
spa_log_debug(impl->log, "Virtualization %s found in DMI (%s)",
s, dmi_vendors[i]);
impl->vm_type = dmi_vendor_table[j].id;
s, *dv);
impl->vm_type = t->id;
goto done;
}
}

View file

@ -351,11 +351,9 @@ static const struct format_info format_info[] = {
static const struct format_info *fourcc_to_format_info(uint32_t fourcc)
{
size_t i;
for (i = 0; i < SPA_N_ELEMENTS(format_info); i++) {
if (format_info[i].fourcc == fourcc)
return &format_info[i];
SPA_FOR_EACH_ELEMENT_VAR(format_info, i) {
if (i->fourcc == fourcc)
return i;
}
return NULL;
}
@ -363,11 +361,9 @@ static const struct format_info *fourcc_to_format_info(uint32_t fourcc)
#if 0
static const struct format_info *video_format_to_format_info(uint32_t format)
{
int i;
for (i = 0; i < SPA_N_ELEMENTS(format_info); i++) {
if (format_info[i].format == format)
return &format_info[i];
SPA_FOR_EACH_ELEMENT_VAR(format_info, i) {
if (i->format == format)
return i;
}
return NULL;
}
@ -381,10 +377,11 @@ static const struct format_info *find_format_info_by_media_type(uint32_t type,
size_t i;
for (i = startidx; i < SPA_N_ELEMENTS(format_info); i++) {
if ((format_info[i].media_type == type) &&
(format_info[i].media_subtype == subtype) &&
(format == 0 || format_info[i].format == format))
return &format_info[i];
const struct format_info *fi = &format_info[i];
if ((fi->media_type == type) &&
(fi->media_subtype == subtype) &&
(format == 0 || fi->format == format))
return fi;
}
return NULL;
}