diff mbox series

[ovs-dev,v2] jsonrpc: Sort JSON objects only if debug is on

Message ID 20210924101744.30065-1-anton.ivanov@cambridgegreys.com
State Deferred
Headers show
Series [ovs-dev,v2] jsonrpc: Sort JSON objects only if debug is on | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test fail github build: failed

Commit Message

Anton Ivanov Sept. 24, 2021, 10:17 a.m. UTC
From: Anton Ivanov <anton.ivanov@cambridgegreys.com>

There is no point to sort JSON objects when nobody is
observing them. Machines do not care if it is sorted or
not.

Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com>
---
 lib/jsonrpc.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c
index c8ce5362e..18777f4d6 100644
--- a/lib/jsonrpc.c
+++ b/lib/jsonrpc.c
@@ -802,7 +802,15 @@  jsonrpc_msg_to_string(const struct jsonrpc_msg *m)
 {
     struct jsonrpc_msg *copy = jsonrpc_msg_clone(m);
     struct json *json = jsonrpc_msg_to_json(copy);
-    char *s = json_to_string(json, JSSF_SORT);
+    char *s;
+    if (VLOG_IS_DBG_ENABLED()) {
+        /* We need json sorted only if a human is looking
+         * at it. No point to sort it if debug is not on.
+         */
+        s = json_to_string(json, JSSF_SORT);
+    } else {
+        s = json_to_string(json, 0);
+    }
     json_destroy(json);
     return s;
 }