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<http://clickemailmkt.eldorado.org.br/ls/click?upn=UPoxpeIcHnAcbUZyo7TTaswyiVb1TXP3jEbQqiiJKKGsxOn8hBEs5ZsMLQfXkKuKXZ7MVDg0ij9eG8HV4TXI75dBzDiNGLxQ8Xx5PzCVNt6TpGrzBbU-2Biu0o69X5ce-2FW-2FOk1uUipuK0fZnWXJEgbRw-3D-3DJY4T_wWk-2BG6VvNBoa1YzxYjhCdFS9IfANIaBzDSklR1NyyrKOI1wj0P-2BdBFcuO4FnHcsA1MyHu0ly1Yt3oDMp7KKdJPM68iKuI2jiRH5v4B0d8wf3chU3qy5n5iXWnW1QjSaNFHOgELzxaP-2FnesTeBgJ5dFkjH4f279sVQpOtyjw5xAqj34M6pgNRAxVvuXif4IWDcVzXg1FzfYlEfkKzr9vvpA3Hg8kitwMtlU3zwbQUBCgL30fQoJPcRPMGKyOY8RmoAlXNqTJYDYIvqmfnI7KLUvw6vKB5R-2B5q1FJRAzX7H-2BmF0NnDET6jMLuIqtCcVIch>

Departamento Computação Embarcada

Analista de Software Trainee

Aviso Legal - Disclaimer<https://www.eldorado.org.br/disclaimer.html>

Reply via email to