Minor optimizations to sensors_feature_get_type():

* We no longer support any single type, so no need to handle this case.
* We can start looking for "_" at offset 3 rather than the beginning
  of the string (the shortest valid prefix is "in0", 3 characters.)


git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4631 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare committed 2007-07-19 20:50:17 +00:00
1 parent c5b2eabf08
commit 5d33dd3e68
1 file changed
+8 -15
+8 -15
View File
@@ -522,8 +522,6 @@ struct feature_subtype_match
struct feature_type_match
{
const char *name;
sensors_feature_type type;
const struct feature_subtype_match *submatches;
};
@@ -568,10 +566,10 @@ static const struct feature_subtype_match cpu_matches[] = {
};
static struct feature_type_match matches[] = {
{ "temp%d%c", SENSORS_FEATURE_UNKNOWN, temp_matches },
{ "in%d%c", SENSORS_FEATURE_UNKNOWN, in_matches },
{ "fan%d%c", SENSORS_FEATURE_UNKNOWN, fan_matches },
{ "cpu%d%c", SENSORS_FEATURE_UNKNOWN, cpu_matches },
{ "temp%d%c", temp_matches },
{ "in%d%c", in_matches },
{ "fan%d%c", fan_matches },
{ "cpu%d%c", cpu_matches },
};
/* Return the feature type and channel number based on the feature name */
@@ -585,18 +583,13 @@ sensors_feature_type sensors_feature_get_type(const char *name, int *nr)
if ((count = sscanf(name, matches[i].name, nr, &c)))
break;
if (i == ARRAY_SIZE(matches)) /* no match */
return SENSORS_FEATURE_UNKNOWN;
else if (count == 1) /* single type */
return matches[i].type;
/* assert: count == 2 */
if (c != '_')
return SENSORS_FEATURE_UNKNOWN;
if (i == ARRAY_SIZE(matches) || count != 2 || c != '_')
return SENSORS_FEATURE_UNKNOWN; /* no match */
submatches = matches[i].submatches;
name = strchr(name + 3, '_') + 1;
for (i = 0; submatches[i].name != NULL; i++)
if (!strcmp(strchr(name, '_') + 1, submatches[i].name))
if (!strcmp(name, submatches[i].name))
return submatches[i].type;
return SENSORS_FEATURE_UNKNOWN;