Skip to content

Commit

Permalink
jsonrpc: use json_to_ds to speed up jsonrpc_send
Browse files Browse the repository at this point in the history
This change reuses the string length that available from 'ds', saving
a strlen() call.

Signed-off-by: Andy Zhou <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
azhou-nicira committed Sep 1, 2015
1 parent 37e2372 commit 71cc59f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/jsonrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ jsonrpc_send(struct jsonrpc *rpc, struct jsonrpc_msg *msg)
{
struct ofpbuf *buf;
struct json *json;
struct ds ds = DS_EMPTY_INITIALIZER;
size_t length;
char *s;

Expand All @@ -249,8 +250,9 @@ jsonrpc_send(struct jsonrpc *rpc, struct jsonrpc_msg *msg)
jsonrpc_log_msg(rpc, "send", msg);

json = jsonrpc_msg_to_json(msg);
s = json_to_string(json, 0);
length = strlen(s);
json_to_ds(json, 0, &ds);
length = ds.length;
s = ds_steal_cstr(&ds);
json_destroy(json);

buf = xmalloc(sizeof *buf);
Expand Down

0 comments on commit 71cc59f

Please sign in to comment.