Skip to content

Commit

Permalink
WTF::map in NativePromise to build Vectors
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=263176
rdar://116991334

Reviewed by Chris Dumez.

No change in functional behaviour.

* Source/WTF/wtf/NativePromise.h:

Canonical link: https://commits.webkit.org/269382@main
  • Loading branch information
jyavenard committed Oct 16, 2023
1 parent d91d0b6 commit 0f9d5af
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions Source/WTF/wtf/NativePromise.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,10 @@ class NativePromise final : public NativePromiseBase, public ConvertibleToNative

m_resolveValues[index] = std::forward<ResolveValueType_>(resolveValue);
if (!--m_outstandingPromises) {
Vector<ResolveValueType> resolveValues;
resolveValues.reserveInitialCapacity(m_resolveValues.size());
for (auto&& resolveValue : m_resolveValues)
resolveValues.append(WTFMove(resolveValue.value()));

m_producer->resolve(WTFMove(resolveValues));
m_producer->resolve(WTF::map(std::exchange(m_resolveValues, { }), [](auto&& resolveValue) {
return WTFMove(*resolveValue);
}));
m_producer = nullptr;
m_resolveValues.clear();
}
}

Expand All @@ -548,7 +544,6 @@ class NativePromise final : public NativePromiseBase, public ConvertibleToNative
// Already resolved or rejected.
return;
}

m_producer->reject(std::forward<RejectValueType_>(rejectValue));
m_producer = nullptr;
m_resolveValues.clear();
Expand Down Expand Up @@ -581,11 +576,9 @@ class NativePromise final : public NativePromiseBase, public ConvertibleToNative

m_results[index].emplace(maybeMove(result));
if (!--m_outstandingPromises) {
Vector<Result> results(m_results.size(), [&](size_t index) {
return WTFMove(*m_results[index]);
});
m_results.clear();
m_producer->resolve(WTFMove(results));
m_producer->resolve(WTF::map(std::exchange(m_results, { }), [](auto&& result) {
return WTFMove(*result);
}));
m_producer = nullptr;
}
}
Expand Down

0 comments on commit 0f9d5af

Please sign in to comment.