Skip to content

Commit

Permalink
append refactoring for speed of list construction
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Apr 1, 2024
1 parent 3cdc451 commit 2c83b82
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/org/rascalmpl/library/lang/box/util/Box2Text.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -345,51 +345,49 @@ private Text AA(list[Row] table, Box c, list[Alignment] alignments, Options opts
list[int] maxWidths = Awidth(rows);
list[Box] vargs = [];

for (list[Box] row <- rows) {
list[Box] hargs = [];

for (<cell, Alignment a, maxWidth> <- zip3(row, alignments, maxWidths)) {
vargs = for (list[Box] row <- rows) {
hargs = for (<cell, Alignment a, maxWidth> <- zip3(row, alignments, maxWidths)) {
int width=cell.width;

// int h= opts.hs;
switch(a) {
case l(): {
// b.hs=maxWidth - width+h; /*left alignment */
if (maxWidth - width > 0) {
hargs += H([cell, SPACE(maxWidth - width)], hs=0);
append H([cell, SPACE(maxWidth - width)], hs=0);
}
else {
hargs += cell;
append cell;
}
}
case r(): {
// b.hs=maxWidth - width+h; /*left alignment */
if (maxWidth - width > 0) {
hargs += H([SPACE(maxWidth - width), cell], hs=0);
append H([SPACE(maxWidth - width), cell], hs=0);
}
else {
hargs += cell;
append cell;
}
}
case c(): {
if (maxWidth - width > 1) {
hargs += H([
append H([
SPACE((maxWidth - width) / 2),
cell,
SPACE((maxWidth - width) / 2)
], hs=0);
}
else if (maxWidth - width == 1) {
hargs += H([cell, SPACE(maxWidth - width)], hs=0);
append H([cell, SPACE(maxWidth - width)], hs=0);
}
else {
hargs += cell;
append cell;
}
}
}
}

vargs += H(hargs, hs=opts.hs);
append H(hargs, hs=opts.hs);
}

return O(V(vargs), c, opts, m);
Expand Down

0 comments on commit 2c83b82

Please sign in to comment.