From patchwork Tue Jul 14 09:39:00 2015
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Pavel Fedin
X-Patchwork-Id: 494953
Return-Path:
X-Original-To: incoming@patchwork.ozlabs.org
Delivered-To: patchwork-incoming@bilbo.ozlabs.org
Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])
(using TLSv1 with cipher AES256-SHA (256/256 bits))
(No client certificate requested)
by ozlabs.org (Postfix) with ESMTPS id 0C567140319
for ;
Tue, 14 Jul 2015 19:39:40 +1000 (AEST)
Received: from localhost ([::1]:58706 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.71) (envelope-from
)
id 1ZEwgc-0001Cf-4A
for incoming@patchwork.ozlabs.org; Tue, 14 Jul 2015 05:39:38 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:54024)
by lists.gnu.org with esmtp (Exim 4.71)
(envelope-from ) id 1ZEwg8-0000Ms-7N
for qemu-devel@nongnu.org; Tue, 14 Jul 2015 05:39:09 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
(envelope-from ) id 1ZEwg4-0001Ip-WD
for qemu-devel@nongnu.org; Tue, 14 Jul 2015 05:39:08 -0400
Received: from mailout3.w1.samsung.com ([210.118.77.13]:21828)
by eggs.gnu.org with esmtp (Exim 4.71)
(envelope-from ) id 1ZEwg4-0001IY-R6
for qemu-devel@nongnu.org; Tue, 14 Jul 2015 05:39:04 -0400
Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245])
by mailout3.w1.samsung.com
(Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5
2014)) with ESMTP id <0NRH009X31H2D440@mailout3.w1.samsung.com> for
qemu-devel@nongnu.org; Tue, 14 Jul 2015 10:39:02 +0100 (BST)
X-AuditID: cbfec7f5-f794b6d000001495-b0-55a4d8b6ec27
Received: from eusync3.samsung.com ( [203.254.199.213])
by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 8B.A8.05269.6B8D4A55;
Tue, 14 Jul 2015 10:39:02 +0100 (BST)
Received: from localhost ([106.109.131.169])
by eusync3.samsung.com (Oracle Communications Messaging Server
7.0.5.31.0 64bit (built May 5 2014))
with ESMTPA id <0NRH0029P1H2LY20@eusync3.samsung.com>; Tue,
14 Jul 2015 10:39:02 +0100 (BST)
From: Pavel Fedin
To: qemu-devel@nongnu.org
Date: Tue, 14 Jul 2015 12:39:00 +0300
Message-id:
X-Mailer: git-send-email 1.9.5.msysgit.0
In-reply-to:
References:
In-reply-to:
References:
X-Brightmail-Tracker:
H4sIAAAAAAAAA+NgFuphluLIzCtJLcpLzFFi42I5/e/4Vd1tN5aEGlx6oG7RvKnY4ubVo0wW
x3t3sDgwezy5tpnJY/Ppao+9n3+zBDBHcdmkpOZklqUW6dslcGV8XvGNtaBVqmLOnY1MDYyL
BbsYOTkkBEwkjrw+wAJhi0lcuLeeDcQWEljKKNFxxK6LkQvI/sYo8ebvFEaQBJuAusTprx/A
GkQEJCV+d51mBrGZBXIkeibsAGsWFnCWWLZ9FiuIzSKgKjFt+QOwXl6BaIm5u78wQSzTkFj0
ZQ5YPaeAucS0JYcZIRabSXz7/ZAdl/gERv4FjAyrGEVTS5MLipPSc430ihNzi0vz0vWS83M3
MULC6OsOxqXHrA4xCnAwKvHwTrBcEirEmlhWXJl7iFGCg1lJhNdiI1CINyWxsiq1KD++qDQn
tfgQozQHi5I478xd70OEBNITS1KzU1MLUotgskwcnFINjN3Opp7qdi0M5rXCkbnTu2dPrvvm
ZaqUuj5GObuj5WvOpcm3S+V/WOdOsX3imKy7uKVHX/2z9Hf5b3qTFot8WuYib2P9x/p/R1dj
1kJL2+9qJ45cf1rWdLLLW+cJ20W/sJUeyQskt2w7qPzxelrZgXAVe14frzN3Au20/3Pmchrm
VwSfYONQYinOSDTUYi4qTgQArien/x8CAAA=
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
recognized.
X-Received-From: 210.118.77.13
Cc: Peter Crosthwaite ,
=?UTF-8?q?Andreas=20F=C3=A4rber?=
Subject: [Qemu-devel] [PATCH v4 1/2] QOM: Introduce
object_property_add_single()
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id:
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org
Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org
Refactoring of object_property_add() before performance optimization of the
array expansion code
Signed-off-by: Pavel Fedin
Reviewed-by: Peter Crosthwaite
---
qom/object.c | 67 ++++++++++++++++++++++++++++++++++++------------------------
1 file changed, 40 insertions(+), 27 deletions(-)
diff --git a/qom/object.c b/qom/object.c
index eea8edf..ba63777 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -830,35 +830,14 @@ void object_unref(Object *obj)
}
}
-ObjectProperty *
-object_property_add(Object *obj, const char *name, const char *type,
- ObjectPropertyAccessor *get,
- ObjectPropertyAccessor *set,
- ObjectPropertyRelease *release,
- void *opaque, Error **errp)
+static ObjectProperty *
+object_property_add_single(Object *obj, const char *name, const char *type,
+ ObjectPropertyAccessor *get,
+ ObjectPropertyAccessor *set,
+ ObjectPropertyRelease *release,
+ void *opaque, Error **errp)
{
ObjectProperty *prop;
- size_t name_len = strlen(name);
-
- if (name_len >= 3 && !memcmp(name + name_len - 3, "[*]", 4)) {
- int i;
- ObjectProperty *ret;
- char *name_no_array = g_strdup(name);
-
- name_no_array[name_len - 3] = '\0';
- for (i = 0; ; ++i) {
- char *full_name = g_strdup_printf("%s[%d]", name_no_array, i);
-
- ret = object_property_add(obj, full_name, type, get, set,
- release, opaque, NULL);
- g_free(full_name);
- if (ret) {
- break;
- }
- }
- g_free(name_no_array);
- return ret;
- }
QTAILQ_FOREACH(prop, &obj->properties, node) {
if (strcmp(prop->name, name) == 0) {
@@ -883,6 +862,40 @@ object_property_add(Object *obj, const char *name, const char *type,
return prop;
}
+ObjectProperty *
+object_property_add(Object *obj, const char *name, const char *type,
+ ObjectPropertyAccessor *get,
+ ObjectPropertyAccessor *set,
+ ObjectPropertyRelease *release,
+ void *opaque, Error **errp)
+{
+ size_t name_len = strlen(name);
+ char *name_no_array;
+ ObjectProperty *ret;
+ int i;
+
+ if (name_len < 3 || memcmp(&name[name_len - 3], "[*]", 4)) {
+ return object_property_add_single(obj, name, type,
+ get, set, release, opaque, errp);
+ }
+
+ name_no_array = g_strdup(name);
+
+ name_no_array[name_len - 3] = '\0';
+ for (i = 0; ; ++i) {
+ char *full_name = g_strdup_printf("%s[%d]", name_no_array, i);
+
+ ret = object_property_add(obj, full_name, type, get, set,
+ release, opaque, NULL);
+ g_free(full_name);
+ if (ret) {
+ break;
+ }
+ }
+ g_free(name_no_array);
+ return ret;
+}
+
ObjectProperty *object_property_find(Object *obj, const char *name,
Error **errp)
{