aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-09-03 13:02:47 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-09-03 13:02:47 +0200
commit9b56bf541667ce1b4d408cd4e23bc51a44ae9267 (patch)
treed2c39193240132d81b77446cbecee15a4c0c8af2 /libbb
parent81254ed3875f7be81b98266866de7f990bcd06c8 (diff)
downloadbusybox-w32-9b56bf541667ce1b4d408cd4e23bc51a44ae9267.tar.gz
busybox-w32-9b56bf541667ce1b4d408cd4e23bc51a44ae9267.tar.bz2
busybox-w32-9b56bf541667ce1b4d408cd4e23bc51a44ae9267.zip
lineedit: stop using permanent int_buf[] (16k!): allocate it
Now it is allocated temporarily only for the duretion of prefix generation, and also we only allocate the needed size, not maximally possible. function old new delta build_match_prefix 579 590 +11 remove_chunk 43 28 -15 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 11/-15) Total: -4 bytes Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/lineedit.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index fff5c1a89..e212a1aa8 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -154,7 +154,6 @@ struct lineedit_statics {
154 /* Formerly these were big buffers on stack: */ 154 /* Formerly these were big buffers on stack: */
155#if ENABLE_FEATURE_TAB_COMPLETION 155#if ENABLE_FEATURE_TAB_COMPLETION
156 char input_tab__matchBuf[MAX_LINELEN]; 156 char input_tab__matchBuf[MAX_LINELEN];
157 int16_t find_match__int_buf[MAX_LINELEN + 1]; /* need to have 9 bits at least */
158#endif 157#endif
159}; 158};
160 159
@@ -821,9 +820,8 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type)
821 * not Unicode chars. Therefore it works correctly even in Unicode mode. 820 * not Unicode chars. Therefore it works correctly even in Unicode mode.
822 */ 821 */
823#define QUOT (UCHAR_MAX+1) 822#define QUOT (UCHAR_MAX+1)
824#define int_buf (S.find_match__int_buf)
825#define dbg_bmp 0 823#define dbg_bmp 0
826static void remove_chunk(int beg, int end) 824static void remove_chunk(int16_t *int_buf, int beg, int end)
827{ 825{
828 /* beg must be <= end */ 826 /* beg must be <= end */
829 if (beg == end) 827 if (beg == end)
@@ -843,11 +841,11 @@ static NOINLINE int build_match_prefix(char *matchBuf)
843{ 841{
844 int i, j; 842 int i, j;
845 int command_mode; 843 int command_mode;
846/* Were local, but it used too much stack */ 844 int16_t *int_buf;
847/* int16_t int_buf[MAX_LINELEN + 1]; */
848 845
849 if (dbg_bmp) printf("\n%s\n", matchBuf); 846 if (dbg_bmp) printf("\n%s\n", matchBuf);
850 847
848 int_buf = xmalloc(sizeof(int_buf[0]) * (strlen(matchBuf) + 1));
851 i = 0; 849 i = 0;
852 while ((int_buf[i] = (unsigned char)matchBuf[i]) != '\0') 850 while ((int_buf[i] = (unsigned char)matchBuf[i]) != '\0')
853 i++; 851 i++;
@@ -855,7 +853,7 @@ static NOINLINE int build_match_prefix(char *matchBuf)
855 /* Mark every \c as "quoted c" */ 853 /* Mark every \c as "quoted c" */
856 for (i = j = 0; matchBuf[i]; i++, j++) { 854 for (i = j = 0; matchBuf[i]; i++, j++) {
857 if (matchBuf[i] == '\\') { 855 if (matchBuf[i] == '\\') {
858 remove_chunk(j, j + 1); 856 remove_chunk(int_buf, j, j + 1);
859 int_buf[j] |= QUOT; 857 int_buf[j] |= QUOT;
860 i++; 858 i++;
861 } 859 }
@@ -871,7 +869,7 @@ static NOINLINE int build_match_prefix(char *matchBuf)
871 if (cur == '\'' || cur == '"') { 869 if (cur == '\'' || cur == '"') {
872 if (!in_quote || (cur == in_quote)) { 870 if (!in_quote || (cur == in_quote)) {
873 in_quote ^= cur; 871 in_quote ^= cur;
874 remove_chunk(i, i + 1); 872 remove_chunk(int_buf, i, i + 1);
875 continue; 873 continue;
876 } 874 }
877 } 875 }
@@ -894,7 +892,7 @@ static NOINLINE int build_match_prefix(char *matchBuf)
894 } else if (cur == '|' && prev == '>') { 892 } else if (cur == '|' && prev == '>') {
895 continue; 893 continue;
896 } 894 }
897 remove_chunk(0, i + 1 + (cur == int_buf[i + 1])); 895 remove_chunk(int_buf, 0, i + 1 + (cur == int_buf[i + 1]));
898 i = -1; /* back to square 1 */ 896 i = -1; /* back to square 1 */
899 } 897 }
900 } 898 }
@@ -908,12 +906,12 @@ static NOINLINE int build_match_prefix(char *matchBuf)
908 * not commands c*. Therefore we don't drop 906 * not commands c*. Therefore we don't drop
909 * `cmd` entirely, we replace it with single `. 907 * `cmd` entirely, we replace it with single `.
910 */ 908 */
911 remove_chunk(i, j); 909 remove_chunk(int_buf, i, j);
912 goto next; 910 goto next;
913 } 911 }
914 } 912 }
915 /* No closing ` - command mode, remove all up to ` */ 913 /* No closing ` - command mode, remove all up to ` */
916 remove_chunk(0, i + 1); 914 remove_chunk(int_buf, 0, i + 1);
917 break; 915 break;
918 next: ; 916 next: ;
919 } 917 }
@@ -925,7 +923,7 @@ static NOINLINE int build_match_prefix(char *matchBuf)
925 */ 923 */
926 for (i = 0; int_buf[i]; i++) { 924 for (i = 0; int_buf[i]; i++) {
927 if (int_buf[i] == '(' || int_buf[i] == '{') { 925 if (int_buf[i] == '(' || int_buf[i] == '{') {
928 remove_chunk(0, i + 1); 926 remove_chunk(int_buf, 0, i + 1);
929 i = -1; /* hack increment */ 927 i = -1; /* hack increment */
930 } 928 }
931 } 929 }
@@ -934,7 +932,7 @@ static NOINLINE int build_match_prefix(char *matchBuf)
934 for (i = 0; int_buf[i]; i++) 932 for (i = 0; int_buf[i]; i++)
935 if (int_buf[i] != ' ') 933 if (int_buf[i] != ' ')
936 break; 934 break;
937 remove_chunk(0, i); 935 remove_chunk(int_buf, 0, i);
938 936
939 /* Determine completion mode */ 937 /* Determine completion mode */
940 command_mode = FIND_EXE_ONLY; 938 command_mode = FIND_EXE_ONLY;
@@ -961,7 +959,7 @@ static NOINLINE int build_match_prefix(char *matchBuf)
961 for (--i; i >= 0; i--) { 959 for (--i; i >= 0; i--) {
962 int cur = int_buf[i]; 960 int cur = int_buf[i];
963 if (cur == ' ' || cur == '<' || cur == '>' || cur == '|' || cur == '&') { 961 if (cur == ' ' || cur == '<' || cur == '>' || cur == '|' || cur == '&') {
964 remove_chunk(0, i + 1); 962 remove_chunk(int_buf, 0, i + 1);
965 break; 963 break;
966 } 964 }
967 } 965 }
@@ -970,11 +968,12 @@ static NOINLINE int build_match_prefix(char *matchBuf)
970 i = 0; 968 i = 0;
971 while ((matchBuf[i] = int_buf[i]) != '\0') 969 while ((matchBuf[i] = int_buf[i]) != '\0')
972 i++; 970 i++;
971 free(int_buf);
972
973 if (dbg_bmp) printf("final matchBuf:'%s'\n", matchBuf); 973 if (dbg_bmp) printf("final matchBuf:'%s'\n", matchBuf);
974 974
975 return command_mode; 975 return command_mode;
976} 976}
977#undef int_buf
978 977
979/* 978/*
980 * Display by column (original idea from ls applet, 979 * Display by column (original idea from ls applet,