Changeset 4759

Show
Ignore:
Timestamp:
09/05/07 10:19:09 (6 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".

Location:
lm-sensors/branches/lm-sensors-3.0.0/lib
Files:
2 modified

Legend:

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

    r4758 r4759  
    9393                                                      int feature) 
    9494{ 
    95         int i, j; 
    96         const sensors_chip_feature *features; 
     95        int i; 
    9796 
    9897        for (i = 0; i < sensors_proc_chips_count; i++) 
    9998                if (sensors_match_chip(&sensors_proc_chips[i].chip, chip)) { 
    100                         features = sensors_proc_chips[i].feature; 
    101                         for (j = 0; features[j].data.name; j++) 
    102                                 if (features[j].data.number == feature) 
    103                                         return features + j; 
     99                        return sensors_proc_chips[i].feature + feature; 
    104100                } 
    105101        return NULL; 
  • 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        }