From: Sebastian Harl Date: Fri, 2 Jan 2015 14:53:54 +0000 (+0100) Subject: utils unixsock: Avoid memory allocations in common cases. X-Git-Tag: sysdb-0.7.0~84 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=640f3e7e8c9a1ad846bcb8adcde9789892c5dadb;p=sysdb.git utils unixsock: Avoid memory allocations in common cases. --- diff --git a/src/utils/unixsock.c b/src/utils/unixsock.c index 6536641..7522171 100644 --- a/src/utils/unixsock.c +++ b/src/utils/unixsock.c @@ -107,7 +107,7 @@ sdb_unixsock_client_process_one_line(sdb_unixsock_client_t *client, for (i = 0; i < column_count; ++i) { char *next; - if (! line) { /* this must no happen */ + if (! line) { /* this must not happen */ sdb_log(SDB_LOG_ERR, "unixsock: Unexpected EOL while " "parsing line (expected %i columns delimited by '%s'; " "got %i): %s", column_count, delim, @@ -125,9 +125,15 @@ sdb_unixsock_client_process_one_line(sdb_unixsock_client_t *client, ++next; } - if (sdb_data_parse(line, - types ? types[i] : SDB_TYPE_STRING, &data[i])) - return -1; + if (types && (types[i] != SDB_TYPE_STRING)) { + if (sdb_data_parse(line, types[i], &data[i])) + return -1; + } + else { + /* Avoid a copy in common cases */ + data[i].type = SDB_TYPE_STRING; + data[i].data.string = line; + } line = next; } @@ -136,7 +142,8 @@ sdb_unixsock_client_process_one_line(sdb_unixsock_client_t *client, return -1; for (i = 0; i < column_count; ++i) - sdb_data_free_datum(&data[i]); + if (types && (types[i] != SDB_TYPE_STRING)) + sdb_data_free_datum(&data[i]); return 0; } /* sdb_unixsock_client_process_one_line */