top: switch to malloced "globals".
This seems to be more efficient: function old new delta clearmems - 28 +28 display_process_list 1001 1018 +17 read_cpu_jiffy 171 177 +6 do_stats 194 198 +4 reset_term 20 23 +3 topmem_sort 63 65 +2 mult_lvl_cmp 44 45 +1 get_jiffy_counts 247 248 +1 display_topmem_process_list 549 546 -3 top_main 912 879 -33 handle_input 630 549 -81 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 7/3 up/down: 62/-117) Total: -55 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
9832bbaba9
commit
d80302db99
13
procps/top.c
13
procps/top.c
@ -116,7 +116,6 @@
|
|||||||
//kbuild:lib-$(CONFIG_TOP) += top.o
|
//kbuild:lib-$(CONFIG_TOP) += top.o
|
||||||
|
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
#include "common_bufsiz.h"
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct top_status_t {
|
typedef struct top_status_t {
|
||||||
@ -154,6 +153,8 @@ typedef int (*cmp_funcp)(top_status_t *P, top_status_t *Q);
|
|||||||
|
|
||||||
enum { SORT_DEPTH = 3 };
|
enum { SORT_DEPTH = 3 };
|
||||||
|
|
||||||
|
/* Screens wider than this are unlikely */
|
||||||
|
enum { LINE_BUF_SIZE = 512 - 64 };
|
||||||
|
|
||||||
struct globals {
|
struct globals {
|
||||||
top_status_t *top;
|
top_status_t *top;
|
||||||
@ -192,10 +193,9 @@ struct globals {
|
|||||||
#if ENABLE_FEATURE_TOP_INTERACTIVE
|
#if ENABLE_FEATURE_TOP_INTERACTIVE
|
||||||
char kbd_input[KEYCODE_BUFFER_SIZE];
|
char kbd_input[KEYCODE_BUFFER_SIZE];
|
||||||
#endif
|
#endif
|
||||||
char line_buf[80];
|
char line_buf[LINE_BUF_SIZE];
|
||||||
}; //FIX_ALIASING; - large code growth
|
};
|
||||||
enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) };
|
#define G (*ptr_to_globals)
|
||||||
#define G (*(struct globals*)bb_common_bufsiz1)
|
|
||||||
#define top (G.top )
|
#define top (G.top )
|
||||||
#define ntop (G.ntop )
|
#define ntop (G.ntop )
|
||||||
#define sort_field (G.sort_field )
|
#define sort_field (G.sort_field )
|
||||||
@ -213,8 +213,7 @@ enum { LINE_BUF_SIZE = COMMON_BUFSIZE - offsetof(struct globals, line_buf) };
|
|||||||
#define total_pcpu (G.total_pcpu )
|
#define total_pcpu (G.total_pcpu )
|
||||||
#define line_buf (G.line_buf )
|
#define line_buf (G.line_buf )
|
||||||
#define INIT_G() do { \
|
#define INIT_G() do { \
|
||||||
setup_common_bufsiz(); \
|
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
|
||||||
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
|
|
||||||
BUILD_BUG_ON(LINE_BUF_SIZE <= 80); \
|
BUILD_BUG_ON(LINE_BUF_SIZE <= 80); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user