@@ -54,13 +54,15 @@ class Builder {
5454
5555 for (auto & param : params) {
5656 func->params .push_back (param.type );
57- func->localIndices [param.name ] = func->localNames .size ();
58- func->localNames .push_back (param.name );
57+ Index index = func->localNames .size ();
58+ func->localIndices [param.name ] = index;
59+ func->localNames [index] = param.name ;
5960 }
6061 for (auto & var : vars) {
6162 func->vars .push_back (var.type );
62- func->localIndices [var.name ] = func->localNames .size ();
63- func->localNames .push_back (var.name );
63+ Index index = func->localNames .size ();
64+ func->localIndices [var.name ] = index;
65+ func->localNames [index] = var.name ;
6466 }
6567
6668 return func;
@@ -321,15 +323,17 @@ class Builder {
321323 func->params .push_back (type);
322324 Index index = func->localNames .size ();
323325 func->localIndices [name] = index;
324- func->localNames . push_back ( name) ;
326+ func->localNames [index] = name;
325327 return index;
326328 }
327329
328330 static Index addVar (Function* func, Name name, WasmType type) {
329331 // always ok to add a var, it does not affect other indices
330332 Index index = func->getNumLocals ();
331- if (name.is ()) func->localIndices [name] = index;
332- func->localNames .push_back (name);
333+ if (name.is ()) {
334+ func->localIndices [name] = index;
335+ func->localNames [index] = name;
336+ }
333337 func->vars .emplace_back (type);
334338 return index;
335339 }
0 commit comments