Show
Ignore:
Timestamp:
09/05/07 10:19:09 (7 years ago)
Author:
khali
Message:

Renumber the features linearly, so that feature number N is at
position N in the array. This allows for O(1) look-ups, as opposed
to O(N) before. This makes sensors_lookup_feature_nr() 2.4 times
faster in my real-world tests, resulting in a 6% performance boost
on average in the runtime part of "sensors".

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/lib/sysfs.c

    r4758 r4759  
    176176                        dyn_features[fnum] = features[i]; 
    177177                        fnum++; 
     178                } 
     179        } 
     180 
     181        /* Renumber the features linearly, so that feature number N is at 
     182           position N in the array. This allows for O(1) look-ups. */ 
     183        for (i = 0; i < fnum; i++) { 
     184                int j, old; 
     185 
     186                old = dyn_features[i].data.number; 
     187                dyn_features[i].data.number = i; 
     188                for (j = i + 1; 
     189                     j < fnum && dyn_features[j].data.mapping != SENSORS_NO_MAPPING; 
     190                     j++) { 
     191                        if (dyn_features[j].data.mapping == old) 
     192                                dyn_features[j].data.mapping = i; 
    178193                } 
    179194        }