mirror of
https://github.com/qemu/qemu.git
synced 2026-05-19 04:03:23 +00:00
qobject: Use GString instead of QString to accumulate JSON
QString supports modifying its string, but it's quite limited: you can only append. The remaining callers use it for building an initial string, never for modifying it later. Use of GString for building the initial string is actually more convenient here. Change qobject_to_json() & friends to do that. Once all such uses are replaced this way, QString can become immutable. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20201211171152.146877-5-armbru@redhat.com>
This commit is contained in:
@@ -66,6 +66,25 @@ QString *qstring_from_str(const char *str)
|
||||
return qstring_from_substr(str, 0, strlen(str));
|
||||
}
|
||||
|
||||
/**
|
||||
* qstring_from_gstring(): Convert a GString to a QString
|
||||
*
|
||||
* Return strong reference.
|
||||
*/
|
||||
|
||||
QString *qstring_from_gstring(GString *gstr)
|
||||
{
|
||||
QString *qstring;
|
||||
|
||||
qstring = g_malloc(sizeof(*qstring));
|
||||
qobject_init(QOBJECT(qstring), QTYPE_QSTRING);
|
||||
qstring->length = gstr->len;
|
||||
qstring->capacity = gstr->allocated_len;
|
||||
qstring->string = g_string_free(gstr, false);
|
||||
return qstring;
|
||||
}
|
||||
|
||||
|
||||
static void capacity_increase(QString *qstring, size_t len)
|
||||
{
|
||||
if (qstring->capacity < (qstring->length + len)) {
|
||||
|
||||
Reference in New Issue
Block a user