qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Anthony Liguori <aliguori@us.ibm.com>,
	Andreas Faerber <afaerber@suse.de>,
	Aurelien Jarno <aurelien@aurel32.net>,
	mst@redhat.com
Subject: [Qemu-devel] [PATCH for-1.5 9/9] qom: simplify object_class_dynamic_cast, part 2
Date: Fri, 10 May 2013 14:16:43 +0200	[thread overview]
Message-ID: <1368188203-3407-10-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1368188203-3407-1-git-send-email-pbonzini@redhat.com>

Detect ambiguous matches right away, without going through all
interfaces first.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qom/object.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/qom/object.c b/qom/object.c
index f82f12c..c69e6a3 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -455,7 +455,6 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename,
 ObjectClass *object_class_dynamic_cast(ObjectClass *class,
                                        const char *typename)
 {
-    ObjectClass *ret = NULL;
     TypeImpl *target_type;
 
     if (!class) {
@@ -475,27 +474,26 @@ ObjectClass *object_class_dynamic_cast(ObjectClass *class,
 
     if (class->interfaces &&
             type_is_ancestor(target_type, type_interface)) {
-        int found = 0;
+        ObjectClass *ret = NULL;
         GSList *i;
 
         for (i = class->interfaces; i; i = i->next) {
             ObjectClass *target_class = i->data;
 
             if (type_is_ancestor(target_class->type, target_type)) {
+                /* If the match is ambiguous, don't allow a cast */
+                if (ret) {
+                    ret = NULL;
+                }
                 ret = target_class;
-                found++;
             }
          }
-
-        /* The match was ambiguous, don't allow a cast */
-        if (found > 1) {
-            ret = NULL;
-        }
+        return ret;
     } else if (type_is_ancestor(class->type, target_type)) {
-        ret = class;
+        return class;
+    } else {
+        return NULL;
     }
-
-    return ret;
 }
 
 ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class,
-- 
1.8.1.4

  parent reply	other threads:[~2013-05-10 12:17 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-10 12:16 [Qemu-devel] [PATCH for-1.5 0/9] Disable expensive QOM cast debugging for official releases Paolo Bonzini
2013-05-10 12:16 ` [Qemu-devel] [PATCH for-1.5 1/9] qom: improve documentation of cast functions Paolo Bonzini
2013-05-10 12:16 ` [Qemu-devel] [PATCH for-1.5 2/9] qom: allow casting of a NULL class Paolo Bonzini
2013-05-10 12:16 ` [Qemu-devel] [PATCH for-1.5 3/9] qom: add a fast path to object_class_dynamic_cast Paolo Bonzini
2013-05-10 12:16 ` [Qemu-devel] [PATCH for-1.5 4/9] qom: pass file/line/function to asserting casts Paolo Bonzini
2013-05-10 12:16 ` [Qemu-devel] [PATCH for-1.5 5/9] qom: trace " Paolo Bonzini
2013-05-10 12:16 ` [Qemu-devel] [PATCH for-1.5 6/9] qom: allow turning cast debugging off Paolo Bonzini
2013-05-10 12:16 ` [Qemu-devel] [PATCH for-1.5 7/9] build: disable QOM cast debugging for official releases Paolo Bonzini
2013-05-10 12:16 ` [Qemu-devel] [PATCH for-1.5 8/9] qom: simplify object_class_dynamic_cast, part 1 Paolo Bonzini
2013-05-10 17:52   ` Anthony Liguori
2013-05-10 12:16 ` Paolo Bonzini [this message]
2013-05-10 13:01 ` [Qemu-devel] [PATCH for-1.5 0/9] Disable expensive QOM cast debugging for official releases Anthony Liguori
2013-05-10 13:08   ` Paolo Bonzini
2013-05-10 13:23     ` Andreas Färber
2013-05-10 13:30       ` Paolo Bonzini
2013-05-10 14:22         ` Aurelien Jarno
2013-05-10 14:39         ` Anthony Liguori
2013-05-10 14:59           ` Paolo Bonzini
2013-05-10 17:41             ` Anthony Liguori
2013-05-10 19:00               ` Aurelien Jarno
2013-05-10 19:35                 ` Anthony Liguori
2013-05-10 20:59               ` Paolo Bonzini
2013-05-10 23:06                 ` Anthony Liguori
2013-05-11  7:59                   ` Paolo Bonzini
2013-05-11  7:23                 ` Aurelien Jarno
2013-05-10 14:27     ` Anthony Liguori
2013-05-10 14:46       ` Aurelien Jarno
2013-05-10 15:04         ` Andreas Färber
2013-05-10 15:56 ` Aurelien Jarno
2013-05-10 16:18   ` Andreas Färber
2013-05-10 16:40     ` Paolo Bonzini
2013-05-10 18:50   ` Anthony Liguori
2013-05-13 16:46 ` Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1368188203-3407-10-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=afaerber@suse.de \
    --cc=aliguori@us.ibm.com \
    --cc=aurelien@aurel32.net \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).