Skip to content

Commit 1755a85

Browse files
committed
libsnmp: Optimize read_config_save_objid()
Make this function slightly faster by eliminating a strlen() call. Declare the 'oid' input parameter const. Remove a superfluous cast.
1 parent ea6c54f commit 1755a85

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

include/net-snmp/library/read_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ extern "C" {
106106
oid ** objid,
107107
size_t * len);
108108
NETSNMP_IMPORT
109-
char *read_config_save_objid(char *saveto, oid * objid,
109+
char *read_config_save_objid(char *saveto, const oid * objid,
110110
size_t len);
111111
NETSNMP_IMPORT
112112
char *read_config_read_data(int type, char *readfrom,

snmplib/read_config.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,7 +2126,7 @@ read_config_read_octet_string_const(const char *readfrom, u_char ** str,
21262126
* read_config_save_objid(): saves an objid as a numerical string
21272127
*/
21282128
char *
2129-
read_config_save_objid(char *saveto, oid * objid, size_t len)
2129+
read_config_save_objid(char *saveto, const oid *objid, size_t len)
21302130
{
21312131
int i;
21322132

@@ -2139,10 +2139,9 @@ read_config_save_objid(char *saveto, oid * objid, size_t len)
21392139
/*
21402140
* in case len=0, this makes it easier to read it back in
21412141
*/
2142-
for (i = 0; i < (int) len; i++) {
2143-
sprintf(saveto, ".%" NETSNMP_PRIo "d", objid[i]);
2144-
saveto += strlen(saveto);
2145-
}
2142+
for (i = 0; i < len; i++)
2143+
saveto += sprintf(saveto, ".%" NETSNMP_PRIo "d", objid[i]);
2144+
21462145
return saveto;
21472146
}
21482147

0 commit comments

Comments
 (0)