vi: speed up some string ops

This commit is contained in:
Denis Vlasenko 2007-12-23 02:36:51 +00:00
parent 528a8b9769
commit f882f08627

View File

@ -1162,9 +1162,9 @@ static void Hit_Return(void)
{
char c;
standout_start(); // start reverse video
standout_start();
write1("[Hit return to continue]");
standout_end(); // end reverse video
standout_end();
while ((c = get_one_char()) != '\n' && c != '\r')
continue;
redraw(TRUE); // force redraw all
@ -1179,14 +1179,11 @@ static int next_tabstop(int col)
static void sync_cursor(char *d, int *row, int *col)
{
char *beg_cur; // begin and end of "d" line
char *end_scr; // begin and end of screen
char *tp;
int cnt, ro, co;
beg_cur = begin_line(d); // first char of cur line
end_scr = end_screen(); // last char of screen
if (beg_cur < screenbegin) {
// "d" is before top line on screen
// how many lines do we have to move
@ -1199,7 +1196,10 @@ static void sync_cursor(char *d, int *row, int *col)
screenbegin = prev_line(screenbegin);
}
}
} else if (beg_cur > end_scr) {
} else {
char *end_scr; // begin and end of screen
end_scr = end_screen(); // last char of screen
if (beg_cur > end_scr) {
// "d" is after bottom line on screen
// how many lines do we have to move
cnt = count_lines(end_scr, beg_cur);
@ -1213,6 +1213,7 @@ static void sync_cursor(char *d, int *row, int *col)
end_scr = end_line(end_scr);
}
}
}
// "d" is on screen- find out which row
tp = screenbegin;
for (ro = 0; ro < rows - 1; ro++) { // drive "ro" to correct row
@ -1273,22 +1274,28 @@ static void sync_cursor(char *d, int *row, int *col)
//----- Text Movement Routines ---------------------------------
static char *begin_line(char *p) // return pointer to first char cur line
{
while (p > text && p[-1] != '\n')
p--; // go to cur line B-o-l
if (p > text) {
p = memrchr(text, '\n', p - text);
if (!p)
return text;
return p + 1;
}
return p;
}
static char *end_line(char *p) // return pointer to NL of cur line line
{
while (p < end - 1 && *p != '\n')
p++; // go to cur line E-o-l
if (p < end - 1) {
p = memchr(p, '\n', end - p - 1);
if (!p)
return end - 1;
}
return p;
}
static char *dollar_line(char *p) // return pointer to just before NL line
{
while (p < end - 1 && *p != '\n')
p++; // go to cur line E-o-l
p = end_line(p);
// Try to stay off of the Newline
if (*p == '\n' && (p - begin_line(p)) > 0)
p--;
@ -1326,7 +1333,8 @@ static char *end_screen(void)
return q;
}
static int count_lines(char * start, char * stop) // count line from start to stop
// count line from start to stop
static int count_lines(char *start, char *stop)
{
char *q;
int cnt;
@ -1337,10 +1345,12 @@ static int count_lines(char * start, char * stop) // count line from start to st
stop = q;
}
cnt = 0;
stop = end_line(stop); // get to end of this line
for (q = start; q <= stop && q <= end - 1; q++) {
if (*q == '\n')
stop = end_line(stop);
while (start <= stop && start <= end - 1) {
start = end_line(start);
if (*start == '\n')
cnt++;
start++;
}
return cnt;
}
@ -2837,12 +2847,16 @@ static void refresh(int full_screen)
// compare text[] to screen[] and mark screen[] lines that need updating
for (li = 0; li < rows - 1; li++) {
int cs, ce; // column start & end
char *out_buf;
// format current text line
char *out_buf = format_line(tp, li);
out_buf = format_line(tp, li);
// skip to the end of the current text[] line
while (tp < end && *tp++ != '\n')
continue;
if (tp < end) {
char *t = memchr(tp, '\n', end - tp);
if (!t) t = end - 1;
tp = t + 1;
}
// see if there are any changes between vitual screen and out_buf
changed = FALSE; // assume no change