This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 1/3] <fd_to_filename.h>: Add type safety and port to Hurd
* Adhemerval Zanella:
> Do we really such optimization which results in somewhat complicate
> code? Couldn't we use something simple as:
>
> char *
> __fd_to_filename (int descriptor, struct fd_to_filename *storage)
> {
> char *buf = storage->buffer;
> int i, j;
>
> for (i = 0; (buf[i] = FD_TO_FILENAME_PREFIX[i]); i++);
> if (descriptor == 0)
> {
> buf[i] = '0';
> buf[i+1] = '\0';
> return storage->buffer;
> }
>
> for (j = descriptor; j != 0; j /= 10, i++);
> buf[i] = '\0';
> for (; descriptor != 0; descriptor /= 10)
> buf[--i] = '0' + descriptor % 10;
>
> return storage->buffer;
> }
I don't have a strong opinion about this (but I think we should probably
keep the mempcpy). Most descriptors will be fairly small, so the
smaller code size is probably more important.
Thanks,
Florian