Vitezslav Samel <vitezslav(a)samel.cz> writes:
On Tue, Aug 28, 2012 at 02:20:23PM +0200, Nikola Pajkovsky wrote:
> Vitezslav Samel <vitezslav(a)samel.cz> writes:
>
> > The test if we need to update the display is the same in 5 files;
> > make this a function: code is more readable, code is smaller,
> > code is (marginally) faster (I eliminated 64-bit multiply).
> >
> > Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
> > ---
> > src/deskman.c | 17 +++++++++++++++++
> > src/deskman.h | 1 +
> > src/detstats.c | 15 +++++----------
> > src/hostmon.c | 15 +++++----------
> > src/ifstats.c | 15 +++++----------
> > src/iptraf-ng-compat.h | 3 +++
> > src/itrafmon.c | 15 +++++----------
> > src/options.h | 2 --
> > src/packet.c | 2 +-
> > src/pktsize.c | 15 +++++----------
> > src/serv.c | 15 +++++----------
> > 11 files changed, 52 insertions(+), 63 deletions(-)
> >
> > diff --git a/src/deskman.c b/src/deskman.c
> > index 25940dc..e0a76cf 100644
> > --- a/src/deskman.c
> > +++ b/src/deskman.c
> > @@ -14,6 +14,7 @@ deskman.c - desktop management routines
> > #include "tui/winops.h"
> >
> > #include "deskman.h"
> > +#include "options.h"
> >
> > /* Attribute variables */
> >
> > @@ -194,6 +195,22 @@ void printlargenum(unsigned long long i, WINDOW * win)
> > wprintw(win, "%8lluT", i / 1000000000000ULL);
> > }
> >
> > +int update_needed(const struct timeval *now, const struct timeval *last)
> > +{
> > + unsigned long msecs = timeval_diff_msec(now, last);
> > + if (options.updrate == 0) {
> > + if (msecs >= DEFAULT_UPDATE_DELAY)
> > + return 1;
> > + else
> > + return 0;
> > + } else {
> > + if (msecs >= (options.updrate * 1000UL))
> > + return 1;
> > + else
> > + return 0;
> > + }
> > +}
>
> I'm not sure if that is right name for that function. update_needed
> doesn't give me any hit, what will be updated, or will it 'something'
> update inside itself.
Any recomendations? screen_update_needed() ?
Vita
You can have, need_update_screen(...) which will return 0/1 then
int do_update_screen(...) that really update screen according to
need_update_screen.
the biggest pain in the ass is that part
- if (((options.updrate == 0)
- && (unow - updtime_usec >= DEFAULT_UPDATE_DELAY))
- || ((options.updrate != 0)
- && (now - updtime >= options.updrate))) {
+ if (update_needed(&tv, &updtime)) {
printdetails(&ifcounts, statwin);
update_panels();
doupdate();
- updtime_usec = unow;
- updtime = now;
+
+ updtime = tv;
}
which do printdetails. Others simply calls update_panels and doupdate.
--
Nikola