Bug 1648440 - Use std::find_if and IIFE instead of custom loops in ScriptLoader. r=dom-workers-and-storage-reviewers,asuth

Differential Revision: https://phabricator.services.mozilla.com/D81057
This commit is contained in:
Simon Giesecke 2020-06-26 16:17:29 +00:00
Родитель a793606305
Коммит ea7a3f8c57
1 изменённых файлов: 26 добавлений и 21 удалений

Просмотреть файл

@ -1489,33 +1489,38 @@ class ScriptLoaderRunnable final : public nsIRunnable, public nsINamed {
mWorkerPrivate->WorkerScriptLoaded();
}
uint32_t firstIndex = UINT32_MAX;
uint32_t lastIndex = UINT32_MAX;
const auto [firstIndex,
lastIndex] = [this]() -> std::pair<uint32_t, uint32_t> {
// Find firstIndex based on whether mExecutionScheduled is unset.
const auto begin = mLoadInfos.begin();
const auto end = mLoadInfos.end();
auto foundFirstIt =
std::find_if(begin, end, [](const ScriptLoadInfo& loadInfo) {
return !loadInfo.mExecutionScheduled;
});
// Find firstIndex based on whether mExecutionScheduled is unset.
for (uint32_t index = 0; index < mLoadInfos.Length(); index++) {
if (!mLoadInfos[index].mExecutionScheduled) {
firstIndex = index;
break;
// Find lastIndex based on whether mChannel is set, and update
// mExecutionScheduled on the ones we're about to schedule.
if (foundFirstIt == end) {
return std::pair(UINT32_MAX, UINT32_MAX);
}
}
// Find lastIndex based on whether mChannel is set, and update
// mExecutionScheduled on the ones we're about to schedule.
if (firstIndex != UINT32_MAX) {
for (uint32_t index = firstIndex; index < mLoadInfos.Length(); index++) {
ScriptLoadInfo& loadInfo = mLoadInfos[index];
const auto foundLastIt =
std::find_if(foundFirstIt, end, [](ScriptLoadInfo& loadInfo) {
if (!loadInfo.Finished()) {
return true;
}
if (!loadInfo.Finished()) {
break;
}
// We can execute this one.
loadInfo.mExecutionScheduled = true;
// We can execute this one.
loadInfo.mExecutionScheduled = true;
return false;
});
lastIndex = index;
}
}
return std::pair(foundFirstIt - begin, foundLastIt == foundFirstIt
? UINT32_MAX
: foundLastIt - begin - 1);
}();
// This is the last index, we can unused things before the exection of the
// script and the stopping of the sync loop.