[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2 3/5] qemu-char: Convert udp backend to QAPI
From: |
Peter Maydell |
Subject: |
Re: [Qemu-devel] [PATCH v2 3/5] qemu-char: Convert udp backend to QAPI |
Date: |
Tue, 2 Sep 2014 21:30:21 +0100 |
On 2 September 2014 21:04, Eric Blake <address@hidden> wrote:
> On 09/02/2014 04:24 AM, Peter Maydell wrote:
>> +
>> + if (host == NULL || strlen(host) == 0) {
>> + host = "localhost";
>> + }
>> + if (port == NULL || strlen(port) == 0) {
>> + error_setg(errp, "chardev: udp: remote port not specified");
>
> In the common case of these strings being non-empty, you end up having
> to hunt for the end of the string only to then throw that information
> away. Rather than 'strlen(foo) == 0)', it's slightly faster to check
> '*foo' for being a non-NUL byte.
I think that's a lot less clear to read, and in fact the
compiler is entirely capable of turning "strlen(x) == 0"
into "check whether *x is 0":
mnementh$ cat /tmp/zz9.c
#include <string.h>
int is_empty_string(const char *s)
{
return (strlen(s) == 0);
}
mnementh$ gcc -g -Wall -O2 -o /tmp/zz9.o -c /tmp/zz9.c
mnementh$ objdump --disassemble /tmp/zz9.o
/tmp/zz9.o: file format elf32-i386
Disassembly of section .text:
00000000 <is_empty_string>:
0: 8b 44 24 04 mov 0x4(%esp),%eax
4: 80 38 00 cmpb $0x0,(%eax)
7: 0f 94 c0 sete %al
a: 0f b6 c0 movzbl %al,%eax
d: c3 ret
thanks
-- PMM
- [Qemu-devel] [PATCH v2 0/5] Convert remaining legacy chardevs to QAPI, Peter Maydell, 2014/09/02
- [Qemu-devel] [PATCH v2 3/5] qemu-char: Convert udp backend to QAPI, Peter Maydell, 2014/09/02
- [Qemu-devel] [PATCH v2 2/5] util/qemu-sockets.c: Support specifying IPv4 or IPv6 in socket_dgram(), Peter Maydell, 2014/09/02
- [Qemu-devel] [PATCH v2 5/5] qemu-char: Rename register_char_driver_qapi() to register_char_driver(), Peter Maydell, 2014/09/02
- [Qemu-devel] [PATCH v2 1/5] qemu-char: Convert socket backend to QAPI, Peter Maydell, 2014/09/02
- [Qemu-devel] [PATCH v2 4/5] qemu-char: Remove register_char_driver() machinery, Peter Maydell, 2014/09/02
- Re: [Qemu-devel] [PATCH v2 0/5] Convert remaining legacy chardevs to QAPI, Paolo Bonzini, 2014/09/09