top: Remove unused handle member

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

top: Remove unused handle member

Klemens Nanni-2
The number of "remaining" processes in the handle struct is not used at
all, it is is only ever set or decremented.

As far as I can tell from CVS logs, this has been the case since

        machine.c revision 1.1
        date: 1997/08/14 14:00:22;  author: downsj;  state: Exp;
        top 3.4, with a few changes.  Still needs more work.

Removing it also gives room for slightly improving the skip semantics
behind the scroll functionality.

Feedback? OK?


Index: machine.c
===================================================================
RCS file: /cvs/src/usr.bin/top/machine.c,v
retrieving revision 1.104
diff -u -p -r1.104 machine.c
--- machine.c 24 Jun 2020 23:56:01 -0000 1.104
+++ machine.c 25 Jun 2020 11:56:32 -0000
@@ -64,7 +64,6 @@ static char **get_proc_args(struct kinfo
 
 struct handle {
  struct kinfo_proc **next_proc; /* points to next valid proc pointer */
- int remaining; /* number of pointers remaining */
 };
 
 /* what we consider to be process size: */
@@ -493,7 +492,6 @@ get_process_info(struct system_info *si,
 
  /* pass back a handle */
  handle.next_proc = pref;
- handle.remaining = active_procs;
  return &handle;
 }
 
@@ -539,11 +537,9 @@ format_comm(struct kinfo_proc *kp)
 }
 
 void
-skip_next_process(struct handle *hndl)
+skip_processes(struct handle *hndl, int n)
 {
- /* find and remember the next proc structure */
- hndl->next_proc++;
- hndl->remaining--;
+ hndl->next_proc += n;
 }
 
 char *
@@ -558,7 +554,6 @@ format_next_process(struct handle *hndl,
 
  /* find and remember the next proc structure */
  pp = *(hndl->next_proc++);
- hndl->remaining--;
 
  cputime = pp->p_rtime_sec + ((pp->p_rtime_usec + 500000) / 1000000);
 
Index: machine.h
===================================================================
RCS file: /cvs/src/usr.bin/top/machine.h,v
retrieving revision 1.28
diff -u -p -r1.28 machine.h
--- machine.h 6 Jan 2020 20:05:10 -0000 1.28
+++ machine.h 25 Jun 2020 11:56:48 -0000
@@ -90,7 +90,7 @@ extern void     get_system_info(struct s
 extern struct handle
 *get_process_info(struct system_info *, struct process_select *,
  int (*) (const void *, const void *));
-extern void     skip_next_process(struct handle *);
+extern void     skip_processes(struct handle *, int);
 extern char    *format_next_process(struct handle *,
  const char *(*)(uid_t, int), pid_t *);
 extern uid_t    proc_owner(pid_t);
Index: top.c
===================================================================
RCS file: /cvs/src/usr.bin/top/top.c,v
retrieving revision 1.102
diff -u -p -r1.102 top.c
--- top.c 6 Jan 2020 20:05:10 -0000 1.102
+++ top.c 25 Jun 2020 11:56:35 -0000
@@ -569,8 +569,7 @@ restart:
  */
  if (skip + active_procs > system_info.p_active)
  skip = system_info.p_active - active_procs;
- for (i = skip; i > 0; i--)
- skip_next_process(processes);
+ skip_processes(processes, skip);
  /* now show the top "n" processes. */
  for (i = 0; i < active_procs; i++) {
  pid_t pid;