Skip to content

Commit 64b067b

Browse files
committed
Faster and cleaner code for 37871be.
1 parent 110d716 commit 64b067b

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

compiler/normalize/simplify.cpp

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -339,20 +339,18 @@ static Tree sigMap(Tree key, tfun f, Tree t)
339339

340340
} else {
341341
tvec br;
342-
int n = t->arity();
343-
bool has_label = isUIInputItem(t) || isUIOutputItem(t);
344-
for (int i = 0; i < n; i++) {
342+
int n = t->arity();
343+
int arg = 0;
344+
if (isUIInputItem(t) || isUIOutputItem(t)) {
345345
// Do not handle labels to avoid simplifying them when using reserved keyword
346-
if (has_label && i == 0) {
347-
br.push_back(t->branch(i));
348-
} else {
349-
br.push_back(sigMap(key, f, t->branch(i)));
350-
}
346+
br.push_back(t->branch(arg));
347+
arg++;
348+
}
349+
for (int i = arg; i < n; i++) {
350+
br.push_back(sigMap(key, f, t->branch(i)));
351351
}
352352

353-
Tree r1 = tree(t->node(), br);
354-
355-
Tree r2 = f(r1);
353+
Tree r2 = f(tree(t->node(), br));
356354
if (r2 == t) {
357355
setProperty(t, key, gGlobal->nil);
358356
} else {
@@ -390,20 +388,18 @@ static Tree sigMapRename(Tree key, Tree env, tfun f, Tree t)
390388

391389
} else {
392390
tvec br;
393-
int n = t->arity();
394-
bool has_label = isUIInputItem(t) || isUIOutputItem(t);
395-
for (int i = 0; i < n; i++) {
391+
int n = t->arity();
392+
int arg = 0;
393+
if (isUIInputItem(t) || isUIOutputItem(t)) {
396394
// Do not handle labels to avoid simplifying them when using reserved keyword
397-
if (has_label && i == 0) {
398-
br.push_back(t->branch(i));
399-
} else {
400-
br.push_back(sigMapRename(key, env, f, t->branch(i)));
401-
}
395+
br.push_back(t->branch(arg));
396+
arg++;
397+
}
398+
for (int i = arg; i < n; i++) {
399+
br.push_back(sigMapRename(key, env, f, t->branch(i)));
402400
}
403401

404-
Tree r1 = tree(t->node(), br);
405-
406-
Tree r2 = f(r1);
402+
Tree r2 = f(tree(t->node(), br));
407403
if (r2 == t) {
408404
setProperty(t, key, gGlobal->nil);
409405
} else {

0 commit comments

Comments
 (0)