mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-03 12:12:06 +00:00
Speed up rendering by caching context pointer ##cons
This commit is contained in:
parent
02989468cd
commit
a9badb01ce
@ -837,14 +837,15 @@ R_API void r_cons_clear(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
R_API void r_cons_reset(void) {
|
R_API void r_cons_reset(void) {
|
||||||
if (C->buffer) {
|
RConsContext *c = C;
|
||||||
C->buffer[0] = '\0';
|
if (c->buffer) {
|
||||||
|
c->buffer[0] = '\0';
|
||||||
}
|
}
|
||||||
C->buffer_len = 0;
|
c->buffer_len = 0;
|
||||||
I->lines = 0;
|
I->lines = 0;
|
||||||
I->lastline = C->buffer;
|
I->lastline = c->buffer;
|
||||||
cons_grep_reset (&C->grep);
|
cons_grep_reset (&c->grep);
|
||||||
C->pageable = true;
|
c->pageable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
R_API const char *r_cons_get_buffer(void) {
|
R_API const char *r_cons_get_buffer(void) {
|
||||||
@ -1110,9 +1111,10 @@ R_API void r_cons_flush(void) {
|
|||||||
}
|
}
|
||||||
} else if (I->maxpage > 0 && C->buffer_len > I->maxpage) {
|
} else if (I->maxpage > 0 && C->buffer_len > I->maxpage) {
|
||||||
#if COUNT_LINES
|
#if COUNT_LINES
|
||||||
|
char *buffer = C->buffer;
|
||||||
int i, lines = 0;
|
int i, lines = 0;
|
||||||
for (i = 0; C->buffer[i]; i++) {
|
for (i = 0; buffer[i]; i++) {
|
||||||
if (C->buffer[i] == '\n') {
|
if (buffer[i] == '\n') {
|
||||||
lines ++;
|
lines ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1499,14 +1501,15 @@ now the console color is reset with each \n (same stuff do it here but in correc
|
|||||||
/* return the aproximated x,y of cursor before flushing */
|
/* return the aproximated x,y of cursor before flushing */
|
||||||
// XXX this function is a huge bottleneck
|
// XXX this function is a huge bottleneck
|
||||||
R_API int r_cons_get_cursor(int *rows) {
|
R_API int r_cons_get_cursor(int *rows) {
|
||||||
|
RConsContext *c = C;
|
||||||
int i, col = 0;
|
int i, col = 0;
|
||||||
int row = 0;
|
int row = 0;
|
||||||
// TODO: we need to handle GOTOXY and CLRSCR ansi escape code too
|
// TODO: we need to handle GOTOXY and CLRSCR ansi escape code too
|
||||||
for (i = 0; i < C->buffer_len; i++) {
|
for (i = 0; i < c->buffer_len; i++) {
|
||||||
// ignore ansi chars, copypasta from r_str_ansi_len
|
// ignore ansi chars, copypasta from r_str_ansi_len
|
||||||
if (C->buffer[i] == 0x1b) {
|
if (c->buffer[i] == 0x1b) {
|
||||||
char ch2 = C->buffer[i + 1];
|
char ch2 = c->buffer[i + 1];
|
||||||
char *str = C->buffer;
|
char *str = c->buffer;
|
||||||
if (ch2 == '\\') {
|
if (ch2 == '\\') {
|
||||||
i++;
|
i++;
|
||||||
} else if (ch2 == ']') {
|
} else if (ch2 == ']') {
|
||||||
@ -1518,7 +1521,7 @@ R_API int r_cons_get_cursor(int *rows) {
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (C->buffer[i] == '\n') {
|
} else if (c->buffer[i] == '\n') {
|
||||||
row++;
|
row++;
|
||||||
col = 0;
|
col = 0;
|
||||||
} else {
|
} else {
|
||||||
@ -2042,8 +2045,10 @@ R_API void r_cons_highlight(const char *word) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
R_API char *r_cons_lastline(int *len) {
|
R_API char *r_cons_lastline(int *len) {
|
||||||
char *b = C->buffer + C->buffer_len;
|
RConsContext *c = C;
|
||||||
while (b > C->buffer) {
|
char *start = c->buffer;
|
||||||
|
char *b = start + c->buffer_len;
|
||||||
|
while (b > start) {
|
||||||
b--;
|
b--;
|
||||||
if (*b == '\n') {
|
if (*b == '\n') {
|
||||||
b++;
|
b++;
|
||||||
@ -2051,8 +2056,8 @@ R_API char *r_cons_lastline(int *len) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (len) {
|
if (len) {
|
||||||
int delta = b - C->buffer;
|
int delta = b - start;
|
||||||
*len = C->buffer_len - delta;
|
*len = c->buffer_len - delta;
|
||||||
}
|
}
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
@ -2060,16 +2065,18 @@ R_API char *r_cons_lastline(int *len) {
|
|||||||
// same as r_cons_lastline(), but len will be the number of
|
// same as r_cons_lastline(), but len will be the number of
|
||||||
// utf-8 characters excluding ansi escape sequences as opposed to just bytes
|
// utf-8 characters excluding ansi escape sequences as opposed to just bytes
|
||||||
R_API char *r_cons_lastline_utf8_ansi_len(int *len) {
|
R_API char *r_cons_lastline_utf8_ansi_len(int *len) {
|
||||||
|
RConsContext *c = C;
|
||||||
if (!len) {
|
if (!len) {
|
||||||
return r_cons_lastline (0);
|
return r_cons_lastline (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *b = C->buffer + C->buffer_len;
|
char *start = c->buffer;
|
||||||
|
char *b = start + c->buffer_len;
|
||||||
int l = 0;
|
int l = 0;
|
||||||
int last_possible_ansi_end = 0;
|
int last_possible_ansi_end = 0;
|
||||||
char ch = '\0';
|
char ch = '\0';
|
||||||
char ch2;
|
char ch2;
|
||||||
while (b > C->buffer) {
|
while (b > start) {
|
||||||
ch2 = ch;
|
ch2 = ch;
|
||||||
ch = *b;
|
ch = *b;
|
||||||
|
|
||||||
@ -2120,21 +2127,23 @@ R_API char *r_cons_swap_ground(const char *col) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
R_API bool r_cons_drop(int n) {
|
R_API bool r_cons_drop(int n) {
|
||||||
if (n > C->buffer_len) {
|
RConsContext *c = C;
|
||||||
C->buffer_len = 0;
|
if (n > c->buffer_len) {
|
||||||
|
c->buffer_len = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
C->buffer_len -= n;
|
c->buffer_len -= n;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
R_API void r_cons_chop(void) {
|
R_API void r_cons_chop(void) {
|
||||||
while (C->buffer_len > 0) {
|
RConsContext *c = C;
|
||||||
char ch = C->buffer[C->buffer_len - 1];
|
while (c->buffer_len > 0) {
|
||||||
|
char ch = c->buffer[c->buffer_len - 1];
|
||||||
if (ch != '\n' && !IS_WHITESPACE (ch)) {
|
if (ch != '\n' && !IS_WHITESPACE (ch)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
C->buffer_len--;
|
c->buffer_len--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user