Reland #11181: replace sort_attrs (insertion sort) with a single insertion (#11201)

This commit is contained in:
Fangrui Song 2018-08-22 16:35:18 -07:00 committed by radare
parent e7028d4e84
commit 3f0b38873d

View File

@ -93,18 +93,6 @@ static const char **attr_at(RConsCanvas *c, int loc) {
return NULL;
}
static void sort_attrs(RConsCanvas *c) {
int i, j;
RConsCanvasAttr value;
for (i = 1; i < c->attrslen; i++) {
value = c->attrs[i];
for (j = i - 1; j >= 0 && c->attrs[j].loc > value.loc; j--) {
c->attrs[j + 1] = c->attrs[j];
}
c->attrs[j + 1] = value;
}
}
static void stamp_attr(RConsCanvas *c, int loc, int length) {
if (!c->color) {
return;
@ -126,10 +114,12 @@ static void stamp_attr(RConsCanvas *c, int loc, int length) {
}
*s = c->attr;
} else {
c->attrs[c->attrslen].loc = loc;
c->attrs[c->attrslen].a = c->attr;
for (i = c->attrslen; i > 0 && loc < c->attrs[i - 1].loc; i--) {
c->attrs[i] = c->attrs[i - 1];
}
c->attrs[i].loc = loc;
c->attrs[i].a = c->attr;
c->attrslen++;
sort_attrs (c);
}
for (i = 1; i < length; i++) {