mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-12-04 21:58:18 +00:00
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:
1 parent
20c98f41b7
commit
7975800ac1
2 files changed
+17
-6
No files matched your search
+15
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user