From 75bd19ec3438496f7aa1ab64cc79849c9e51418d Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Wed, 5 Sep 2007 08:26:26 +0000 Subject: [PATCH] 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 --- lib/sysfs.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/sysfs.c b/lib/sysfs.c index dfbc4882..b1e0ee5f 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -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; } }