qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH for-5.1 4/5] qobject: Eliminate qdict_iter(), use qdict_first


From: Markus Armbruster
Subject: Re: [PATCH for-5.1 4/5] qobject: Eliminate qdict_iter(), use qdict_first(), qdict_next()
Date: Wed, 15 Apr 2020 16:48:02 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)

Eric Blake <address@hidden> writes:

> On 4/15/20 3:30 AM, Markus Armbruster wrote:
>> qdict_iter() has just three uses and no test coverage.  Replace by
>> qdict_first(), qdict_next() for more concise code and less type
>> punning.
>>
>> Signed-off-by: Markus Armbruster <address@hidden>
>> ---
>>   include/qapi/qmp/qdict.h     |  3 --
>>   qapi/qobject-input-visitor.c | 21 +++++++-------
>>   qobject/qdict.c              | 19 -------------
>>   qobject/qjson.c              | 54 +++++++++++++-----------------------
>>   util/qemu-option.c           | 10 ++++++-
>>   5 files changed, 40 insertions(+), 67 deletions(-)
>>
>
>>   static const QListEntry *qobject_input_push(QObjectInputVisitor *qiv,
>>                                               const char *name,
>>                                               QObject *obj, void *qapi)
>>   {
>>       GHashTable *h;
>>       StackObject *tos = g_new0(StackObject, 1);
>> +    QDict *qdict = qobject_to(QDict, obj);
>> +    QList *qlist = qobject_to(QList, obj);
>> +    const QDictEntry *entry;
>>         assert(obj);
>>       tos->name = name;
>>       tos->obj = obj;
>>       tos->qapi = qapi;
>>   -    if (qobject_type(obj) == QTYPE_QDICT) {
>> +    if (qdict) {
>>           h = g_hash_table_new(g_str_hash, g_str_equal);
>> -        qdict_iter(qobject_to(QDict, obj), qdict_add_key, h);
>> +        for (entry = qdict_first(qdict);
>> +             entry;
>> +             entry = qdict_next(qdict, entry)) {
>> +            g_hash_table_insert(h, (void *)qdict_entry_key(entry), NULL);
>
> Is the cast to void* necessary?

It casts away const.

> Otherwise,
> Reviewed-by: Eric Blake <address@hidden>

Thanks!




reply via email to

[Prev in Thread] Current Thread [Next in Thread]