Optimize prefixline in cons/canvas

This commit is contained in:
pancake 2017-02-13 00:58:25 +01:00
parent 29311ec67e
commit ea5740da57

View File

@ -124,11 +124,13 @@ static int get_piece(const char *p, char *chr) {
static char *prefixline(RConsCanvas *c, int *left) {
int x, len;
char *p;
if (!c || strlen (c->b) < (c->y * c->w)) {
int b_len = c->w * c->h; //strlen (c->b); // correct optimization?
int yxw = c->y * c->w;
if (!c || b_len < yxw) {
return NULL;
}
p = c->b + (c->y * c->w);
len = strlen (p) - 1;
p = c->b + yxw;
len = b_len - yxw - 1;
for (x = 0; (p[x] && x < c->x) && x < len; x++) {
if (p[x] == '\n') {
p[x] = ' ';