mirror of
https://github.com/traviscross/mtr.git
synced 2024-09-21 18:37:10 +00:00
performance: make get_iiwidth() to be const function
Change input argument to be a variable, so that optimizer can kick in and take short cuts when possible. Reference; https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes
This commit is contained in:
parent
c1806e9c75
commit
48d859cd7e
10
asn.c
10
asn.c
@ -256,18 +256,18 @@ extern ATTRIBUTE_CONST size_t get_iiwidth_len(void) {
|
||||
return (sizeof(iiwidth) / sizeof((iiwidth)[0]));
|
||||
}
|
||||
|
||||
extern int get_iiwidth(struct mtr_ctl *ctl) {
|
||||
extern ATTRIBUTE_CONST int get_iiwidth(int ipinfo_no) {
|
||||
static const int len = (sizeof(iiwidth) / sizeof((iiwidth)[0]));
|
||||
|
||||
if (ctl->ipinfo_no < len)
|
||||
return iiwidth[ctl->ipinfo_no];
|
||||
return iiwidth[ctl->ipinfo_no % len];
|
||||
if (ipinfo_no < len)
|
||||
return iiwidth[ipinfo_no];
|
||||
return iiwidth[ipinfo_no % len];
|
||||
}
|
||||
|
||||
extern char *fmt_ipinfo(struct mtr_ctl *ctl, ip_t *addr){
|
||||
char *ipinfo = get_ipinfo(ctl, addr);
|
||||
char fmt[8];
|
||||
snprintf(fmt, sizeof(fmt), "%s%%-%ds", ctl->ipinfo_no?"":"AS", get_iiwidth(ctl));
|
||||
snprintf(fmt, sizeof(fmt), "%s%%-%ds", ctl->ipinfo_no?"":"AS", get_iiwidth(ctl->ipinfo_no));
|
||||
snprintf(fmtinfo, sizeof(fmtinfo), fmt, ipinfo?ipinfo:UNKN);
|
||||
return fmtinfo;
|
||||
}
|
||||
|
2
asn.h
2
asn.h
@ -22,5 +22,5 @@ extern void asn_open(struct mtr_ctl *ctl);
|
||||
extern void asn_close(struct mtr_ctl *ctl);
|
||||
extern char *fmt_ipinfo(struct mtr_ctl *ctl, ip_t *addr);
|
||||
extern ATTRIBUTE_CONST size_t get_iiwidth_len(void);
|
||||
extern int get_iiwidth(struct mtr_ctl *ctl);
|
||||
extern ATTRIBUTE_CONST int get_iiwidth(int ipinfo_no);
|
||||
extern int is_printii(struct mtr_ctl *ctl);
|
||||
|
2
curses.c
2
curses.c
@ -687,7 +687,7 @@ extern void mtr_curses_redraw(struct mtr_ctl *ctl)
|
||||
int padding = 30;
|
||||
#ifdef HAVE_IPINFO
|
||||
if (is_printii(ctl))
|
||||
padding += get_iiwidth(ctl);
|
||||
padding += get_iiwidth(ctl->ipinfo_no);
|
||||
#endif
|
||||
int max_cols = maxx<=SAVED_PINGS+padding ? maxx-padding : SAVED_PINGS;
|
||||
startstat = padding - 2;
|
||||
|
Loading…
Reference in New Issue
Block a user