aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-12-23 02:36:51 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-12-23 02:36:51 +0000
commitf882f086278038b7978a75ed33308b9033411ae8 (patch)
treee0b7e91047ca46400f4c3c7843cf95eb25866997
parent528a8b97697ebd84003a64f779bee1b3fb330e16 (diff)
downloadbusybox-w32-f882f086278038b7978a75ed33308b9033411ae8.tar.gz
busybox-w32-f882f086278038b7978a75ed33308b9033411ae8.tar.bz2
busybox-w32-f882f086278038b7978a75ed33308b9033411ae8.zip
vi: speed up some string ops
-rw-r--r--editors/vi.c98
1 files changed, 56 insertions, 42 deletions
diff --git a/editors/vi.c b/editors/vi.c
index f06cad227..b6d4dcf0d 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -1162,9 +1162,9 @@ static void Hit_Return(void)
1162{ 1162{
1163 char c; 1163 char c;
1164 1164
1165 standout_start(); // start reverse video 1165 standout_start();
1166 write1("[Hit return to continue]"); 1166 write1("[Hit return to continue]");
1167 standout_end(); // end reverse video 1167 standout_end();
1168 while ((c = get_one_char()) != '\n' && c != '\r') 1168 while ((c = get_one_char()) != '\n' && c != '\r')
1169 continue; 1169 continue;
1170 redraw(TRUE); // force redraw all 1170 redraw(TRUE); // force redraw all
@@ -1179,16 +1179,13 @@ static int next_tabstop(int col)
1179static void sync_cursor(char *d, int *row, int *col) 1179static void sync_cursor(char *d, int *row, int *col)
1180{ 1180{
1181 char *beg_cur; // begin and end of "d" line 1181 char *beg_cur; // begin and end of "d" line
1182 char *end_scr; // begin and end of screen
1183 char *tp; 1182 char *tp;
1184 int cnt, ro, co; 1183 int cnt, ro, co;
1185 1184
1186 beg_cur = begin_line(d); // first char of cur line 1185 beg_cur = begin_line(d); // first char of cur line
1187 1186
1188 end_scr = end_screen(); // last char of screen
1189
1190 if (beg_cur < screenbegin) { 1187 if (beg_cur < screenbegin) {
1191 // "d" is before top line on screen 1188 // "d" is before top line on screen
1192 // how many lines do we have to move 1189 // how many lines do we have to move
1193 cnt = count_lines(beg_cur, screenbegin); 1190 cnt = count_lines(beg_cur, screenbegin);
1194 sc1: 1191 sc1:
@@ -1199,18 +1196,22 @@ static void sync_cursor(char *d, int *row, int *col)
1199 screenbegin = prev_line(screenbegin); 1196 screenbegin = prev_line(screenbegin);
1200 } 1197 }
1201 } 1198 }
1202 } else if (beg_cur > end_scr) { 1199 } else {
1203 // "d" is after bottom line on screen 1200 char *end_scr; // begin and end of screen
1204 // how many lines do we have to move 1201 end_scr = end_screen(); // last char of screen
1205 cnt = count_lines(end_scr, beg_cur); 1202 if (beg_cur > end_scr) {
1206 if (cnt > (rows - 1) / 2) 1203 // "d" is after bottom line on screen
1207 goto sc1; // too many lines 1204 // how many lines do we have to move
1208 for (ro = 0; ro < cnt - 1; ro++) { 1205 cnt = count_lines(end_scr, beg_cur);
1209 // move screen begin the same amount 1206 if (cnt > (rows - 1) / 2)
1210 screenbegin = next_line(screenbegin); 1207 goto sc1; // too many lines
1211 // now, move the end of screen 1208 for (ro = 0; ro < cnt - 1; ro++) {
1212 end_scr = next_line(end_scr); 1209 // move screen begin the same amount
1213 end_scr = end_line(end_scr); 1210 screenbegin = next_line(screenbegin);
1211 // now, move the end of screen
1212 end_scr = next_line(end_scr);
1213 end_scr = end_line(end_scr);
1214 }
1214 } 1215 }
1215 } 1216 }
1216 // "d" is on screen- find out which row 1217 // "d" is on screen- find out which row
@@ -1271,31 +1272,37 @@ static void sync_cursor(char *d, int *row, int *col)
1271} 1272}
1272 1273
1273//----- Text Movement Routines --------------------------------- 1274//----- Text Movement Routines ---------------------------------
1274static char *begin_line(char * p) // return pointer to first char cur line 1275static char *begin_line(char *p) // return pointer to first char cur line
1275{ 1276{
1276 while (p > text && p[-1] != '\n') 1277 if (p > text) {
1277 p--; // go to cur line B-o-l 1278 p = memrchr(text, '\n', p - text);
1279 if (!p)
1280 return text;
1281 return p + 1;
1282 }
1278 return p; 1283 return p;
1279} 1284}
1280 1285
1281static char *end_line(char * p) // return pointer to NL of cur line line 1286static char *end_line(char *p) // return pointer to NL of cur line line
1282{ 1287{
1283 while (p < end - 1 && *p != '\n') 1288 if (p < end - 1) {
1284 p++; // go to cur line E-o-l 1289 p = memchr(p, '\n', end - p - 1);
1290 if (!p)
1291 return end - 1;
1292 }
1285 return p; 1293 return p;
1286} 1294}
1287 1295
1288static char *dollar_line(char * p) // return pointer to just before NL line 1296static char *dollar_line(char *p) // return pointer to just before NL line
1289{ 1297{
1290 while (p < end - 1 && *p != '\n') 1298 p = end_line(p);
1291 p++; // go to cur line E-o-l
1292 // Try to stay off of the Newline 1299 // Try to stay off of the Newline
1293 if (*p == '\n' && (p - begin_line(p)) > 0) 1300 if (*p == '\n' && (p - begin_line(p)) > 0)
1294 p--; 1301 p--;
1295 return p; 1302 return p;
1296} 1303}
1297 1304
1298static char *prev_line(char * p) // return pointer first char prev line 1305static char *prev_line(char *p) // return pointer first char prev line
1299{ 1306{
1300 p = begin_line(p); // goto begining of cur line 1307 p = begin_line(p); // goto begining of cur line
1301 if (p[-1] == '\n' && p > text) 1308 if (p[-1] == '\n' && p > text)
@@ -1304,7 +1311,7 @@ static char *prev_line(char * p) // return pointer first char prev line
1304 return p; 1311 return p;
1305} 1312}
1306 1313
1307static char *next_line(char * p) // return pointer first char next line 1314static char *next_line(char *p) // return pointer first char next line
1308{ 1315{
1309 p = end_line(p); 1316 p = end_line(p);
1310 if (*p == '\n' && p < end - 1) 1317 if (*p == '\n' && p < end - 1)
@@ -1326,21 +1333,24 @@ static char *end_screen(void)
1326 return q; 1333 return q;
1327} 1334}
1328 1335
1329static int count_lines(char * start, char * stop) // count line from start to stop 1336// count line from start to stop
1337static int count_lines(char *start, char *stop)
1330{ 1338{
1331 char *q; 1339 char *q;
1332 int cnt; 1340 int cnt;
1333 1341
1334 if (stop < start) { // start and stop are backwards- reverse them 1342 if (stop < start) { // start and stop are backwards- reverse them
1335 q = start; 1343 q = start;
1336 start = stop; 1344 start = stop;
1337 stop = q; 1345 stop = q;
1338 } 1346 }
1339 cnt = 0; 1347 cnt = 0;
1340 stop = end_line(stop); // get to end of this line 1348 stop = end_line(stop);
1341 for (q = start; q <= stop && q <= end - 1; q++) { 1349 while (start <= stop && start <= end - 1) {
1342 if (*q == '\n') 1350 start = end_line(start);
1351 if (*start == '\n')
1343 cnt++; 1352 cnt++;
1353 start++;
1344 } 1354 }
1345 return cnt; 1355 return cnt;
1346} 1356}
@@ -1415,11 +1425,11 @@ static void dot_scroll(int cnt, int dir)
1415 for (; cnt > 0; cnt--) { 1425 for (; cnt > 0; cnt--) {
1416 if (dir < 0) { 1426 if (dir < 0) {
1417 // scroll Backwards 1427 // scroll Backwards
1418 // ctrl-Y scroll up one line 1428 // ctrl-Y scroll up one line
1419 screenbegin = prev_line(screenbegin); 1429 screenbegin = prev_line(screenbegin);
1420 } else { 1430 } else {
1421 // scroll Forwards 1431 // scroll Forwards
1422 // ctrl-E scroll down one line 1432 // ctrl-E scroll down one line
1423 screenbegin = next_line(screenbegin); 1433 screenbegin = next_line(screenbegin);
1424 } 1434 }
1425 } 1435 }
@@ -1444,7 +1454,7 @@ static void dot_delete(void) // delete the char at 'dot'
1444 text_hole_delete(dot, dot); 1454 text_hole_delete(dot, dot);
1445} 1455}
1446 1456
1447static char *bound_dot(char * p) // make sure text[0] <= P < "end" 1457static char *bound_dot(char *p) // make sure text[0] <= P < "end"
1448{ 1458{
1449 if (p >= end && end > text) { 1459 if (p >= end && end > text) {
1450 p = end - 1; 1460 p = end - 1;
@@ -1808,7 +1818,7 @@ static char *find_pair(char * p, const char c)
1808 1818
1809#if ENABLE_FEATURE_VI_SETOPTS 1819#if ENABLE_FEATURE_VI_SETOPTS
1810// show the matching char of a pair, () [] {} 1820// show the matching char of a pair, () [] {}
1811static void showmatching(char * p) 1821static void showmatching(char *p)
1812{ 1822{
1813 char *q, *save_dot; 1823 char *q, *save_dot;
1814 1824
@@ -2057,7 +2067,7 @@ static void check_context(char cmd)
2057 } 2067 }
2058} 2068}
2059 2069
2060static char *swap_context(char * p) // goto new context for '' command make this the current context 2070static char *swap_context(char *p) // goto new context for '' command make this the current context
2061{ 2071{
2062 char *tmp; 2072 char *tmp;
2063 2073
@@ -2837,12 +2847,16 @@ static void refresh(int full_screen)
2837 // compare text[] to screen[] and mark screen[] lines that need updating 2847 // compare text[] to screen[] and mark screen[] lines that need updating
2838 for (li = 0; li < rows - 1; li++) { 2848 for (li = 0; li < rows - 1; li++) {
2839 int cs, ce; // column start & end 2849 int cs, ce; // column start & end
2850 char *out_buf;
2840 // format current text line 2851 // format current text line
2841 char *out_buf = format_line(tp, li); 2852 out_buf = format_line(tp, li);
2842 2853
2843 // skip to the end of the current text[] line 2854 // skip to the end of the current text[] line
2844 while (tp < end && *tp++ != '\n') 2855 if (tp < end) {
2845 continue; 2856 char *t = memchr(tp, '\n', end - tp);
2857 if (!t) t = end - 1;
2858 tp = t + 1;
2859 }
2846 2860
2847 // see if there are any changes between vitual screen and out_buf 2861 // see if there are any changes between vitual screen and out_buf
2848 changed = FALSE; // assume no change 2862 changed = FALSE; // assume no change