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".


git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4759 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare committed 2007-09-05 08:19:09 +00:00
1 parent 20c98f41b7
commit 7975800ac1
2 files changed
+17 -6

No files matched your search

+2 -6
View File
@@ -92,15 +92,11 @@ sensors_for_all_config_chips(const sensors_chip_name *name,
const sensors_chip_feature *sensors_lookup_feature_nr(const sensors_chip_name *chip,
int feature)
{
int i, j;
const sensors_chip_feature *features;
int i;
for (i = 0; i < sensors_proc_chips_count; i++)
if (sensors_match_chip(&sensors_proc_chips[i].chip, chip)) {
features = sensors_proc_chips[i].feature;
for (j = 0; features[j].data.name; j++)
if (features[j].data.number == feature)
return features + j;
return sensors_proc_chips[i].feature + feature;
}
return NULL;
}
+15
View File
@@ -178,6 +178,21 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
}
}
/* Renumber the features linearly, so that feature number N is at
position N in the array. This allows for O(1) look-ups. */
for (i = 0; i < fnum; i++) {
int j, old;
old = dyn_features[i].data.number;
dyn_features[i].data.number = i;
for (j = i + 1;
j < fnum && dyn_features[j].data.mapping != SENSORS_NO_MAPPING;
j++) {
if (dyn_features[j].data.mapping == old)
dyn_features[j].data.mapping = i;
}
}
chip->feature = dyn_features;
exit_free: