Minor optimizations in sensors_read_dynamic_chip():

* We don't need to compute the mapping during the first pass: this
  field is overwritten when renumbering the features anyway.
* Only main features have features mapping to them.
* Only subfeatures have mappings, so we can stop the scan at the next
  main feature.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4763 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare committed 2007-09-05 08:26:26 +00:00
1 parent b836fc0b53
commit 75bd19ec34
1 file changed
+9 -9
+9 -9
View File
@@ -137,7 +137,6 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
}
/* fill in the other feature members */
feature.data.number = i;
feature.data.type = type;
if ((type & 0x00FF) == 0) {
@@ -145,7 +144,7 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
feature.data.mapping = SENSORS_NO_MAPPING;
} else {
/* sub feature */
feature.data.mapping = i - i % (MAX_SUB_FEATURES * 2);
/* The mapping is set below after numbering */
if (!(type & 0x10))
feature.data.flags |= SENSORS_COMPUTE_MAPPING;
}
@@ -177,17 +176,18 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
}
}
/* Renumber the features linearly, so that feature number N is at
/* Number 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;
int j;
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)
if (dyn_features[i].data.mapping == SENSORS_NO_MAPPING) {
/* Main feature, set the mapping field of all its
subfeatures */
for (j = i + 1; j < fnum &&
dyn_features[j].data.mapping != SENSORS_NO_MAPPING;
j++)
dyn_features[j].data.mapping = i;
}
}