Commit 2bde2cc7 authored by Clemens Backes's avatar Clemens Backes Committed by V8 LUCI CQ

[wasm][cleanup] Use range-based signature iteration

Instead of hand-coding a loop, use range-based for loops for iterating
signatures. Similarly, {std::transform} can replace a hand-coded loop
for constructing values from return types.

R=thibaudm@chromium.org

Bug: v8:12244
Change-Id: I467656650b731cbcb9ea57c54f5311885bb158dd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3181520Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77054}
parent c5312996
...@@ -1330,13 +1330,10 @@ class WasmDecoder : public Decoder { ...@@ -1330,13 +1330,10 @@ class WasmDecoder : public Decoder {
} }
bool CanReturnCall(const FunctionSig* target_sig) { bool CanReturnCall(const FunctionSig* target_sig) {
if (target_sig == nullptr) return false; if (sig_->return_count() != target_sig->return_count()) return false;
size_t num_returns = sig_->return_count(); auto target_sig_it = target_sig->returns().begin();
if (num_returns != target_sig->return_count()) return false; for (ValueType ret_type : sig_->returns()) {
for (size_t i = 0; i < num_returns; ++i) { if (!IsSubtypeOf(*target_sig_it++, ret_type, this->module_)) return false;
if (!IsSubtypeOf(target_sig->GetReturn(i), sig_->GetReturn(i),
this->module_))
return false;
} }
return true; return true;
} }
...@@ -2650,9 +2647,7 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> { ...@@ -2650,9 +2647,7 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> {
c->reachability = control_at(1)->innerReachability(); c->reachability = control_at(1)->innerReachability();
const WasmTagSig* sig = imm.tag->sig; const WasmTagSig* sig = imm.tag->sig;
EnsureStackSpace(static_cast<int>(sig->parameter_count())); EnsureStackSpace(static_cast<int>(sig->parameter_count()));
for (size_t i = 0, e = sig->parameter_count(); i < e; ++i) { for (ValueType type : sig->parameters()) Push(CreateValue(type));
Push(CreateValue(sig->GetParam(i)));
}
base::Vector<Value> values(stack_ + c->stack_depth, sig->parameter_count()); base::Vector<Value> values(stack_ + c->stack_depth, sig->parameter_count());
current_catch_ = c->previous_catch; // Pop try scope. current_catch_ = c->previous_catch; // Pop try scope.
CALL_INTERFACE_IF_OK_AND_PARENT_REACHABLE(CatchException, imm, c, values); CALL_INTERFACE_IF_OK_AND_PARENT_REACHABLE(CatchException, imm, c, values);
...@@ -5097,9 +5092,8 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> { ...@@ -5097,9 +5092,8 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> {
V8_INLINE ReturnVector CreateReturnValues(const FunctionSig* sig) { V8_INLINE ReturnVector CreateReturnValues(const FunctionSig* sig) {
size_t return_count = sig->return_count(); size_t return_count = sig->return_count();
ReturnVector values(return_count); ReturnVector values(return_count);
for (size_t i = 0; i < return_count; ++i) { std::transform(sig->returns().begin(), sig->returns().end(), values.begin(),
values[i] = CreateValue(sig->GetReturn(i)); [this](ValueType type) { return CreateValue(type); });
}
return values; return values;
} }
V8_INLINE void PushReturns(ReturnVector values) { V8_INLINE void PushReturns(ReturnVector values) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment