top(1): remove unneeded logic

- remove __pure annotations I added earlier for some functions. One
writes to the the arguments as "out" pointers. The
other reads from an array, which while const within the function might
be mutated externally.
- total_change is modified to be at 1, if previously 0, so no if check
is needed.
This commit is contained in:
Eitan Adler 2018-06-13 11:12:52 +00:00
parent a5185adeb6
commit f764243341
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=335049

View File

@ -122,7 +122,7 @@ digits(int val)
* string_index(string, array) - find string in array and return index
*/
int __pure
int
string_index(const char *string, const char * const *array)
{
size_t i = 0;
@ -175,7 +175,7 @@ argparse(char *line, int *cntp)
* useful on for calculating cpu state percentages.
*/
long __pure
long
percentages(int cnt, int *out, long *new, long *old, long *diffs)
{
int i;
@ -210,13 +210,10 @@ percentages(int cnt, int *out, long *new, long *old, long *diffs)
/* calculate percentages based on overall change, rounding up */
half_total = total_change / 2l;
/* Do not divide by 0. Causes Floating point exception */
if(total_change) {
for (i = 0; i < cnt; i++)
{
*out++ = (int)((*diffs++ * 1000 + half_total) / total_change);
}
}
for (i = 0; i < cnt; i++)
{
*out++ = (int)((*diffs++ * 1000 + half_total) / total_change);
}
/* return the total in case the caller wants to use it */
return(total_change);