diff mbox

[v10,07/25] hmp: Cache use of qapi visitor

Message ID 1454075341-13658-8-git-send-email-eblake@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Eric Blake Jan. 29, 2016, 1:48 p.m. UTC
Cache the visitor in a local variable instead of repeatedly
calling the accessor.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

---
v10: resplit 4/37 and 5/37 by action rather than file, retain R-b.
v9: no change
v8: no change
v7: place earlier in series, drop attempts to provide a 'kind' string,
drop bogus avoidance of qmp_object_del() on error
v6: new patch, split from RFC on v5 7/46
---
 hmp.c | 12 +++++++-----
 vl.c  | 12 +++++++-----
 2 files changed, 14 insertions(+), 10 deletions(-)
diff mbox

Patch

diff --git a/hmp.c b/hmp.c
index 9537f7b..6d67f9b 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1658,6 +1658,7 @@  void hmp_object_add(Monitor *mon, const QDict *qdict)
     char *id = NULL;
     OptsVisitor *ov;
     QDict *pdict;
+    Visitor *v;

     opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
     if (err) {
@@ -1666,28 +1667,29 @@  void hmp_object_add(Monitor *mon, const QDict *qdict)

     ov = opts_visitor_new(opts);
     pdict = qdict_clone_shallow(qdict);
+    v = opts_get_visitor(ov);

-    visit_start_struct(opts_get_visitor(ov), NULL, NULL, NULL, 0, &err);
+    visit_start_struct(v, NULL, NULL, NULL, 0, &err);
     if (err) {
         goto out_clean;
     }

     qdict_del(pdict, "qom-type");
-    visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
+    visit_type_str(v, &type, "qom-type", &err);
     if (err) {
         goto out_end;
     }

     qdict_del(pdict, "id");
-    visit_type_str(opts_get_visitor(ov), &id, "id", &err);
+    visit_type_str(v, &id, "id", &err);
     if (err) {
         goto out_end;
     }

-    object_add(type, id, pdict, opts_get_visitor(ov), &err);
+    object_add(type, id, pdict, v, &err);

 out_end:
-    visit_end_struct(opts_get_visitor(ov), &err_end);
+    visit_end_struct(v, &err_end);
     if (!err && err_end) {
         qmp_object_del(id, NULL);
     }
diff --git a/vl.c b/vl.c
index b96590a..24d30f2 100644
--- a/vl.c
+++ b/vl.c
@@ -2827,17 +2827,19 @@  static int object_create(void *opaque, QemuOpts *opts, Error **errp)
     OptsVisitor *ov;
     QDict *pdict;
     bool (*type_predicate)(const char *) = opaque;
+    Visitor *v;

     ov = opts_visitor_new(opts);
     pdict = qemu_opts_to_qdict(opts, NULL);
+    v = opts_get_visitor(ov);

-    visit_start_struct(opts_get_visitor(ov), NULL, NULL, NULL, 0, &err);
+    visit_start_struct(v, NULL, NULL, NULL, 0, &err);
     if (err) {
         goto out;
     }

     qdict_del(pdict, "qom-type");
-    visit_type_str(opts_get_visitor(ov), &type, "qom-type", &err);
+    visit_type_str(v, &type, "qom-type", &err);
     if (err) {
         goto out;
     }
@@ -2846,16 +2848,16 @@  static int object_create(void *opaque, QemuOpts *opts, Error **errp)
     }

     qdict_del(pdict, "id");
-    visit_type_str(opts_get_visitor(ov), &id, "id", &err);
+    visit_type_str(v, &id, "id", &err);
     if (err) {
         goto out;
     }

-    object_add(type, id, pdict, opts_get_visitor(ov), &err);
+    object_add(type, id, pdict, v, &err);
     if (err) {
         goto out;
     }
-    visit_end_struct(opts_get_visitor(ov), &err);
+    visit_end_struct(v, &err);
     if (err) {
         qmp_object_del(id, NULL);
     }