Clean up some lambda definitions
This commit is contained in:
+24
-28
@@ -193,7 +193,6 @@ ALeffectslot *AllocEffectSlot(ALCcontext *context)
|
||||
[](const EffectSlotSubList &entry) noexcept -> bool
|
||||
{ return entry.FreeMask != 0; }
|
||||
);
|
||||
|
||||
auto lidx = static_cast<ALuint>(std::distance(context->mEffectSlotList.begin(), sublist));
|
||||
auto slidx = static_cast<ALuint>(CTZ64(sublist->FreeMask));
|
||||
|
||||
@@ -305,41 +304,38 @@ START_API_FUNC
|
||||
ContextRef context{GetContextRef()};
|
||||
if UNLIKELY(!context) return;
|
||||
|
||||
if(n < 0)
|
||||
SETERR_RETURN(context, AL_INVALID_VALUE,, "Deleting %d effect slots", n);
|
||||
if(n == 0) return;
|
||||
if UNLIKELY(n < 0)
|
||||
context->setError(AL_INVALID_VALUE, "Deleting %d effect slots", n);
|
||||
if UNLIKELY(n <= 0) return;
|
||||
|
||||
std::lock_guard<std::mutex> _{context->mEffectSlotLock};
|
||||
auto effectslots_end = effectslots + n;
|
||||
auto bad_slot = std::find_if(effectslots, effectslots_end,
|
||||
[&context](ALuint id) -> bool
|
||||
auto validate_slot = [&context](const ALuint id) -> bool
|
||||
{
|
||||
ALeffectslot *slot{LookupEffectSlot(context.get(), id)};
|
||||
if UNLIKELY(!slot)
|
||||
{
|
||||
ALeffectslot *slot{LookupEffectSlot(context.get(), id)};
|
||||
if(!slot)
|
||||
{
|
||||
context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", id);
|
||||
return true;
|
||||
}
|
||||
if(ReadRef(slot->ref) != 0)
|
||||
{
|
||||
context->setError(AL_INVALID_NAME, "Deleting in-use effect slot %u", id);
|
||||
return true;
|
||||
}
|
||||
context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", id);
|
||||
return false;
|
||||
}
|
||||
);
|
||||
if(bad_slot != effectslots_end)
|
||||
return;
|
||||
if UNLIKELY(ReadRef(slot->ref) != 0)
|
||||
{
|
||||
context->setError(AL_INVALID_OPERATION, "Deleting in-use effect slot %u", id);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
auto effectslots_end = effectslots + n;
|
||||
auto bad_slot = std::find_if_not(effectslots, effectslots_end, validate_slot);
|
||||
if UNLIKELY(bad_slot != effectslots_end) return;
|
||||
|
||||
// All effectslots are valid, remove and delete them
|
||||
RemoveActiveEffectSlots(effectslots, static_cast<ALuint>(n), context.get());
|
||||
std::for_each(effectslots, effectslots_end,
|
||||
[&context](ALuint sid) -> void
|
||||
{
|
||||
ALeffectslot *slot{LookupEffectSlot(context.get(), sid)};
|
||||
if(slot) FreeEffectSlot(context.get(), slot);
|
||||
}
|
||||
);
|
||||
auto delete_slot = [&context](const ALuint sid) -> void
|
||||
{
|
||||
ALeffectslot *slot{LookupEffectSlot(context.get(), sid)};
|
||||
if(slot) FreeEffectSlot(context.get(), slot);
|
||||
};
|
||||
std::for_each(effectslots, effectslots_end, delete_slot);
|
||||
}
|
||||
END_API_FUNC
|
||||
|
||||
|
||||
+23
-26
@@ -682,36 +682,33 @@ START_API_FUNC
|
||||
std::lock_guard<std::mutex> _{device->BufferLock};
|
||||
|
||||
/* First try to find any buffers that are invalid or in-use. */
|
||||
const ALuint *buffers_end = buffers + n;
|
||||
auto invbuf = std::find_if(buffers, buffers_end,
|
||||
[device, &context](ALuint bid) -> bool
|
||||
auto validate_buffer = [device, &context](const ALuint bid) -> bool
|
||||
{
|
||||
if(!bid) return true;
|
||||
ALbuffer *ALBuf{LookupBuffer(device, bid)};
|
||||
if UNLIKELY(!ALBuf)
|
||||
{
|
||||
if(!bid) return false;
|
||||
ALbuffer *ALBuf = LookupBuffer(device, bid);
|
||||
if UNLIKELY(!ALBuf)
|
||||
{
|
||||
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", bid);
|
||||
return true;
|
||||
}
|
||||
if UNLIKELY(ReadRef(ALBuf->ref) != 0)
|
||||
{
|
||||
context->setError(AL_INVALID_OPERATION, "Deleting in-use buffer %u", bid);
|
||||
return true;
|
||||
}
|
||||
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", bid);
|
||||
return false;
|
||||
}
|
||||
);
|
||||
if LIKELY(invbuf == buffers_end)
|
||||
if UNLIKELY(ReadRef(ALBuf->ref) != 0)
|
||||
{
|
||||
context->setError(AL_INVALID_OPERATION, "Deleting in-use buffer %u", bid);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
const ALuint *buffers_end = buffers + n;
|
||||
auto invbuf = std::find_if_not(buffers, buffers_end, validate_buffer);
|
||||
if UNLIKELY(invbuf != buffers_end) return;
|
||||
|
||||
/* All good. Delete non-0 buffer IDs. */
|
||||
auto delete_buffer = [device](const ALuint bid) -> void
|
||||
{
|
||||
/* All good. Delete non-0 buffer IDs. */
|
||||
std::for_each(buffers, buffers_end,
|
||||
[device](ALuint bid) -> void
|
||||
{
|
||||
ALbuffer *buffer{bid ? LookupBuffer(device, bid) : nullptr};
|
||||
if(buffer) FreeBuffer(device, buffer);
|
||||
}
|
||||
);
|
||||
}
|
||||
ALbuffer *buffer{bid ? LookupBuffer(device, bid) : nullptr};
|
||||
if(buffer) FreeBuffer(device, buffer);
|
||||
};
|
||||
std::for_each(buffers, buffers_end, delete_buffer);
|
||||
}
|
||||
END_API_FUNC
|
||||
|
||||
|
||||
+15
-23
@@ -169,7 +169,6 @@ ALeffect *AllocEffect(ALCdevice *device)
|
||||
[](const EffectSubList &entry) noexcept -> bool
|
||||
{ return entry.FreeMask != 0; }
|
||||
);
|
||||
|
||||
auto lidx = static_cast<ALuint>(std::distance(device->EffectList.begin(), sublist));
|
||||
auto slidx = static_cast<ALuint>(CTZ64(sublist->FreeMask));
|
||||
|
||||
@@ -264,31 +263,24 @@ START_API_FUNC
|
||||
std::lock_guard<std::mutex> _{device->EffectLock};
|
||||
|
||||
/* First try to find any effects that are invalid. */
|
||||
auto validate_effect = [device](const ALuint eid) -> bool
|
||||
{ return !eid || LookupEffect(device, eid) != nullptr; };
|
||||
|
||||
const ALuint *effects_end = effects + n;
|
||||
auto inveffect = std::find_if(effects, effects_end,
|
||||
[device, &context](ALuint eid) -> bool
|
||||
{
|
||||
if(!eid) return false;
|
||||
ALeffect *effect{LookupEffect(device, eid)};
|
||||
if UNLIKELY(!effect)
|
||||
{
|
||||
context->setError(AL_INVALID_NAME, "Invalid effect ID %u", eid);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
);
|
||||
if LIKELY(inveffect == effects_end)
|
||||
auto inveffect = std::find_if_not(effects, effects_end, validate_effect);
|
||||
if UNLIKELY(inveffect != effects_end)
|
||||
{
|
||||
/* All good. Delete non-0 effect IDs. */
|
||||
std::for_each(effects, effects_end,
|
||||
[device](ALuint eid) -> void
|
||||
{
|
||||
ALeffect *effect{eid ? LookupEffect(device, eid) : nullptr};
|
||||
if(effect) FreeEffect(device, effect);
|
||||
}
|
||||
);
|
||||
context->setError(AL_INVALID_NAME, "Invalid effect ID %u", *inveffect);
|
||||
return;
|
||||
}
|
||||
|
||||
/* All good. Delete non-0 effect IDs. */
|
||||
auto delete_effect = [device](ALuint eid) -> void
|
||||
{
|
||||
ALeffect *effect{eid ? LookupEffect(device, eid) : nullptr};
|
||||
if(effect) FreeEffect(device, effect);
|
||||
};
|
||||
std::for_each(effects, effects_end, delete_effect);
|
||||
}
|
||||
END_API_FUNC
|
||||
|
||||
|
||||
+15
-23
@@ -312,7 +312,6 @@ ALfilter *AllocFilter(ALCdevice *device)
|
||||
[](const FilterSubList &entry) noexcept -> bool
|
||||
{ return entry.FreeMask != 0; }
|
||||
);
|
||||
|
||||
auto lidx = static_cast<ALuint>(std::distance(device->FilterList.begin(), sublist));
|
||||
auto slidx = static_cast<ALuint>(CTZ64(sublist->FreeMask));
|
||||
|
||||
@@ -408,31 +407,24 @@ START_API_FUNC
|
||||
std::lock_guard<std::mutex> _{device->FilterLock};
|
||||
|
||||
/* First try to find any filters that are invalid. */
|
||||
auto validate_filter = [device](const ALuint fid) -> bool
|
||||
{ return !fid || LookupFilter(device, fid) != nullptr; };
|
||||
|
||||
const ALuint *filters_end = filters + n;
|
||||
auto invflt = std::find_if(filters, filters_end,
|
||||
[device, &context](ALuint fid) -> bool
|
||||
{
|
||||
if(!fid) return false;
|
||||
ALfilter *filter{LookupFilter(device, fid)};
|
||||
if UNLIKELY(!filter)
|
||||
{
|
||||
context->setError(AL_INVALID_NAME, "Invalid filter ID %u", fid);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
);
|
||||
if LIKELY(invflt == filters_end)
|
||||
auto invflt = std::find_if_not(filters, filters_end, validate_filter);
|
||||
if UNLIKELY(invflt != filters_end)
|
||||
{
|
||||
/* All good. Delete non-0 filter IDs. */
|
||||
std::for_each(filters, filters_end,
|
||||
[device](ALuint fid) -> void
|
||||
{
|
||||
ALfilter *filter{fid ? LookupFilter(device, fid) : nullptr};
|
||||
if(filter) FreeFilter(device, filter);
|
||||
}
|
||||
);
|
||||
context->setError(AL_INVALID_NAME, "Invalid filter ID %u", *invflt);
|
||||
return;
|
||||
}
|
||||
|
||||
/* All good. Delete non-0 filter IDs. */
|
||||
auto delete_filter = [device](const ALuint fid) -> void
|
||||
{
|
||||
ALfilter *filter{fid ? LookupFilter(device, fid) : nullptr};
|
||||
if(filter) FreeFilter(device, filter);
|
||||
};
|
||||
std::for_each(filters, filters_end, delete_filter);
|
||||
}
|
||||
END_API_FUNC
|
||||
|
||||
|
||||
+2
-2
@@ -2110,7 +2110,7 @@ START_API_FUNC
|
||||
std::lock_guard<std::mutex> _{context->mSourceLock};
|
||||
|
||||
/* Check that all Sources are valid */
|
||||
auto validate_source = [&context](ALuint sid) -> bool
|
||||
auto validate_source = [&context](const ALuint sid) -> bool
|
||||
{ return LookupSource(context.get(), sid) != nullptr; };
|
||||
|
||||
const ALuint *sources_end = sources + n;
|
||||
@@ -2122,7 +2122,7 @@ START_API_FUNC
|
||||
}
|
||||
|
||||
/* All good. Delete source IDs. */
|
||||
auto delete_source = [&context](ALuint sid) -> void
|
||||
auto delete_source = [&context](const ALuint sid) -> void
|
||||
{
|
||||
ALsource *src{LookupSource(context.get(), sid)};
|
||||
if(src) FreeSource(context.get(), src);
|
||||
|
||||
Reference in New Issue
Block a user