qemu-devel
[Top][All Lists]
Advanced

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

RE: Better alternative to strncpy in QEMU.


From: Bruno Piazera Larsen
Subject: RE: Better alternative to strncpy in QEMU.
Date: Mon, 12 Apr 2021 12:48:35 +0000

Im not sure about what "better version" means, but my guess would be a faster or more reliable version. If that's the case:

>     for (int i = 0; i < strlen(source); i++) {

Since you're going on ebyte at a time, there's no need to know how big the array is. As a stopping condition you could use source[i] != '\0', which is one less pass through the array.

One other optimization that could be done (but is a bigger headache to implement correctly) would be to cast the char* into uint64_t* (or uint32_t* for 32-bit systems) and copy more bytes at a time. The headache comes from finding a 0 in this longer variable, but you can probably use a similar strategy to freebsd's strlen (https://github.com/freebsd/freebsd-src/blob/main/lib/libc/string/strlen.c).

I'm not sure if it would be a real speedup in most cases, since glibc can use this strategy already), but at least we'd have consistent performance in case some system doesn't use it

Bruno Piazera Larsen

Instituto de Pesquisas ELDORADO

Departamento Computação Embarcada

Analista de Software Trainee

Aviso Legal - Disclaimer


reply via email to

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