jsonrpc: use json_to_ds to speed up jsonrpc_send
authorAndy Zhou <azhou@nicira.com>
Tue, 11 Aug 2015 21:11:58 +0000 (14:11 -0700)
committerAndy Zhou <azhou@nicira.com>
Tue, 1 Sep 2015 22:17:42 +0000 (15:17 -0700)
This change reuses the string length that available from 'ds', saving
a strlen() call.

Signed-off-by: Andy Zhou <azhou@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
lib/jsonrpc.c

index 1e312a2..b48e247 100644 (file)
@@ -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;
 
@@ -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);