aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-06-04 12:21:53 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-06-04 12:21:53 +0000
commitef4bb26f937b6628306742c417305b813d8f2913 (patch)
tree93073c9f6da8f76bc8522ece04f850cc2d08d884
parent821cc25f435fa4b463f20669b2b9baf198ea04c4 (diff)
downloadbusybox-w32-ef4bb26f937b6628306742c417305b813d8f2913.tar.gz
busybox-w32-ef4bb26f937b6628306742c417305b813d8f2913.tar.bz2
busybox-w32-ef4bb26f937b6628306742c417305b813d8f2913.zip
diff: stop using data/bss
function old new delta do_diff 385 436 +51 diff_main 850 895 +45 dump_unified_vec 437 457 +20 prepare 335 334 -1 anychange 1 - -1 suff 4 - -4 status 135 131 -4 static.max_context 4 - -4 start 12 8 -4 pref 4 - -4 member 4 - -4 label2 4 - -4 label1 4 - -4 klist 4 - -4 ixold 4 - -4 ixnew 4 - -4 dl_count 4 - -4 dl 4 - -4 context_vec_start 4 - -4 context_vec_ptr 4 - -4 context_vec_end 4 - -4 context 4 - -4 clistlen 4 - -4 clist 4 - -4 clen 4 - -4 class 4 - -4 J 4 - -4 add_to_dirlist 71 64 -7 slen 8 - -8 sfile 8 - -8 len 8 - -8 file 8 - -8 get_dir 196 185 -11 newcand 97 85 -12 change 351 331 -20 stb2 96 - -96 stb1 96 - -96 diffreg 2835 2717 -118 ------------------------------------------------------------------------------ (add/remove: 0/27 grow/shrink: 3/8 up/down: 116/-482) Total: -366 bytes # size */*/diff.o text data bss dec hex filename 7055 8 305 7368 1cc8 busybox.t2/coreutils/diff.o 7002 0 0 7002 1b5a busybox.t3/coreutils/diff.o
-rw-r--r--coreutils/diff.c120
-rw-r--r--miscutils/nmeter.c9
2 files changed, 79 insertions, 50 deletions
diff --git a/coreutils/diff.c b/coreutils/diff.c
index f6b045b2d..faab287f8 100644
--- a/coreutils/diff.c
+++ b/coreutils/diff.c
@@ -65,36 +65,16 @@
65#define FLAG_U (1<<12) 65#define FLAG_U (1<<12)
66#define FLAG_w (1<<13) 66#define FLAG_w (1<<13)
67 67
68/* The following variables should be static, but gcc currently
69 * creates a much bigger object if we do this. [which version of gcc? --vda] */
70/* 4.x, IIRC also 3.x --bernhard */
71/* Works for gcc 3.4.3. Sizes without and with "static":
72 # size busybox.t[34]/coreutils/diff.o
73 text data bss dec hex filename
74 6969 8 305 7282 1c72 busybox.t3/coreutils/diff.o
75 6969 8 305 7282 1c72 busybox.t4/coreutils/diff.o
76 --vda
77 */
78/* This is the default number of lines of context. */
79static int context = 3;
80static int status;
81static char *start;
82static const char *label1;
83static const char *label2;
84static struct stat stb1, stb2;
85USE_FEATURE_DIFF_DIR(static char **dl;)
86USE_FEATURE_DIFF_DIR(static int dl_count;)
87
88struct cand { 68struct cand {
89 int x; 69 int x;
90 int y; 70 int y;
91 int pred; 71 int pred;
92}; 72};
93 73
94static struct line { 74struct line {
95 int serial; 75 int serial;
96 int value; 76 int value;
97} *file[2]; 77};
98 78
99/* 79/*
100 * The following struct is used to record change information 80 * The following struct is used to record change information
@@ -102,29 +82,79 @@ static struct line {
102 * understand the highly mnemonic field names) 82 * understand the highly mnemonic field names)
103 */ 83 */
104struct context_vec { 84struct context_vec {
105 int a; /* start line in old file */ 85 int a; /* start line in old file */
106 int b; /* end line in old file */ 86 int b; /* end line in old file */
107 int c; /* start line in new file */ 87 int c; /* start line in new file */
108 int d; /* end line in new file */ 88 int d; /* end line in new file */
89};
90
91struct globals {
92 USE_FEATURE_DIFF_DIR(char **dl;)
93 USE_FEATURE_DIFF_DIR(int dl_count;)
94 /* This is the default number of lines of context. */
95 int context;
96 size_t max_context;
97 int status;
98 char *start;
99 const char *label1;
100 const char *label2;
101 struct line *file[2];
102 int *J; /* will be overlaid on class */
103 int *class; /* will be overlaid on file[0] */
104 int *klist; /* will be overlaid on file[0] after class */
105 int *member; /* will be overlaid on file[1] */
106 int clen;
107 int len[2];
108 int pref, suff; /* length of prefix and suffix */
109 int slen[2];
110 bool anychange;
111 long *ixnew; /* will be overlaid on file[1] */
112 long *ixold; /* will be overlaid on klist */
113 struct cand *clist; /* merely a free storage pot for candidates */
114 int clistlen; /* the length of clist */
115 struct line *sfile[2]; /* shortened by pruning common prefix/suffix */
116 struct context_vec *context_vec_start;
117 struct context_vec *context_vec_end;
118 struct context_vec *context_vec_ptr;
119 struct stat stb1, stb2;
109}; 120};
121#define G (*ptr_to_globals)
122#define dl (G.dl )
123#define dl_count (G.dl_count )
124#define context (G.context )
125#define max_context (G.max_context )
126#define status (G.status )
127#define start (G.start )
128#define label1 (G.label1 )
129#define label2 (G.label2 )
130#define file (G.file )
131#define J (G.J )
132#define class (G.class )
133#define klist (G.klist )
134#define member (G.member )
135#define clen (G.clen )
136#define len (G.len )
137#define pref (G.pref )
138#define suff (G.suff )
139#define slen (G.slen )
140#define anychange (G.anychange )
141#define ixnew (G.ixnew )
142#define ixold (G.ixold )
143#define clist (G.clist )
144#define clistlen (G.clistlen )
145#define sfile (G.sfile )
146#define context_vec_start (G.context_vec_start )
147#define context_vec_end (G.context_vec_end )
148#define context_vec_ptr (G.context_vec_ptr )
149#define stb1 (G.stb1 )
150#define stb2 (G.stb2 )
151#define INIT_G() do { \
152 PTR_TO_GLOBALS = xzalloc(sizeof(G)); \
153 context = 3; \
154 max_context = 64; \
155} while (0)
156
110 157
111static int *J; /* will be overlaid on class */
112static int *class; /* will be overlaid on file[0] */
113static int *klist; /* will be overlaid on file[0] after class */
114static int *member; /* will be overlaid on file[1] */
115static int clen;
116static int len[2];
117static int pref, suff; /* length of prefix and suffix */
118static int slen[2];
119static bool anychange;
120static long *ixnew; /* will be overlaid on file[1] */
121static long *ixold; /* will be overlaid on klist */
122static struct cand *clist; /* merely a free storage pot for candidates */
123static int clistlen; /* the length of clist */
124static struct line *sfile[2]; /* shortened by pruning common prefix/suffix */
125static struct context_vec *context_vec_start;
126static struct context_vec *context_vec_end;
127static struct context_vec *context_vec_ptr;
128 158
129 159
130static void print_only(const char *path, size_t dirlen, const char *entry) 160static void print_only(const char *path, size_t dirlen, const char *entry)
@@ -761,8 +791,6 @@ static void print_header(const char *file1, const char *file2)
761static void change(char *file1, FILE * f1, char *file2, FILE * f2, int a, 791static void change(char *file1, FILE * f1, char *file2, FILE * f2, int a,
762 int b, int c, int d) 792 int b, int c, int d)
763{ 793{
764 static size_t max_context = 64;
765
766 if ((a > b && c > d) || (option_mask32 & FLAG_q)) { 794 if ((a > b && c > d) || (option_mask32 & FLAG_q)) {
767 anychange = 1; 795 anychange = 1;
768 return; 796 return;
@@ -1170,6 +1198,8 @@ int diff_main(int argc, char **argv)
1170 char *f1, *f2; 1198 char *f1, *f2;
1171 llist_t *L_arg = NULL; 1199 llist_t *L_arg = NULL;
1172 1200
1201 INIT_G();
1202
1173 /* exactly 2 params; collect multiple -L <label> */ 1203 /* exactly 2 params; collect multiple -L <label> */
1174 opt_complementary = "=2:L::"; 1204 opt_complementary = "=2:L::";
1175 getopt32(argc, argv, "abdiL:NqrsS:tTU:wu" 1205 getopt32(argc, argv, "abdiL:NqrsS:tTU:wu"
diff --git a/miscutils/nmeter.c b/miscutils/nmeter.c
index 3152b74e3..1d58eb2c1 100644
--- a/miscutils/nmeter.c
+++ b/miscutils/nmeter.c
@@ -69,16 +69,16 @@ struct globals {
69#define proc_meminfo (G.proc_meminfo ) 69#define proc_meminfo (G.proc_meminfo )
70#define proc_diskstats (G.proc_diskstats ) 70#define proc_diskstats (G.proc_diskstats )
71#define proc_sys_fs_filenr (G.proc_sys_fs_filenr) 71#define proc_sys_fs_filenr (G.proc_sys_fs_filenr)
72
73// We depend on this being a char[], not char* - we take sizeof() of it
74#define outbuf bb_common_bufsiz1
75
76#define INIT_G() do { \ 72#define INIT_G() do { \
73 PTR_TO_GLOBALS = xzalloc(sizeof(G)); \
77 cur_outbuf = outbuf; \ 74 cur_outbuf = outbuf; \
78 final_str = "\n"; \ 75 final_str = "\n"; \
79 deltanz = delta = 1000000; \ 76 deltanz = delta = 1000000; \
80 } while (0) 77 } while (0)
81 78
79// We depend on this being a char[], not char* - we take sizeof() of it
80#define outbuf bb_common_bufsiz1
81
82static inline void reset_outbuf(void) 82static inline void reset_outbuf(void)
83{ 83{
84 cur_outbuf = outbuf; 84 cur_outbuf = outbuf;
@@ -774,7 +774,6 @@ int nmeter_main(int argc, char **argv)
774 s_stat *s; 774 s_stat *s;
775 char *cur, *prev; 775 char *cur, *prev;
776 776
777 PTR_TO_GLOBALS = xzalloc(sizeof(G));
778 INIT_G(); 777 INIT_G();
779 778
780 xchdir("/proc"); 779 xchdir("/proc");