|
From: | Hao QingFeng |
Subject: | Re: [Qemu-block] [PATCH 2/3] block: Emit modules in bdrv_iterate_format() |
Date: | Wed, 2 Nov 2016 18:52:29 +0800 |
User-agent: | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 |
在 2016-10-13 4:49, Max Reitz 写道:
Sorry for a bit late response. The function looks fine but just some doubt on g_renew in this piece of code(and the legacy), does g_renew(realloc) has much performance impact if it's call many times since alloc and memory copy are both also run many times?Some block drivers may not be loaded yet, but qemu supports them nonetheless. bdrv_iterate_format() should report them, too. Signed-off-by: Max Reitz <address@hidden> --- block.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/block.c b/block.c index e46e4b2..88a1ea5 100644 --- a/block.c +++ b/block.c @@ -2815,6 +2815,24 @@ void bdrv_iterate_format(void (*it)(void *opaque, const char *name), } } + for (i = 0; i < (int)ARRAY_SIZE(block_driver_modules); i++) { + const char *format_name = block_driver_modules[i].format_name; + + if (format_name) { + bool found = false; + int j = count; + + while (formats && j && !found) { + found = !strcmp(formats[--j], format_name); + } + + if (!found) { + formats = g_renew(const char *, formats, count + 1); + formats[count++] = format_name; + } + } + } +
So how about increase the memory for more instead of 1 each time? formats = g_renew(const char *, formats, count + 10); A new counter also needs to be introduced to record the space size. Thanks
qsort(formats, count, sizeof(formats[0]), qsort_strcmp); for (i = 0; i < count; i++) {
-- QingFeng Hao(Robin)
[Prev in Thread] | Current Thread | [Next in Thread] |