This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Use llvm::toLower instead of libc call tolower
ClosedPublic

Authored by MaskRay on Sep 14 2018, 5:37 PM.

Event Timeline

MaskRay created this revision.Sep 14 2018, 5:37 PM
ruiu added a comment.Sep 15 2018, 3:44 AM

What is the point of doing this?

What is the point of doing this?

lld does not call setlocale() so the locale remains default "C". tolower exhibits different behaviors with some locales, e.g.:

setlocale(LC_CTYPE, "de_DE@euro");
printf("%x\n", tolower(0xb4)); => 0xb8

So it has slightly higher overhead. llvm::toLower is more efficient as it compiles to a compare and a conditional jump, as opposed to a libc call if tolower is used.

This is what gdb uses:

https://sourceware.org/git/?p=binutils-gdb.git;a=blob;hb=160fc977b6f33e5ef51f6c1f3cdcb57965c522c8;f=gdb/minsyms.h#l184

#define SYMBOL_HASH_NEXT(hash, c)			\
  ((hash) * 67 + TOLOWER ((unsigned char) (c)) - 113)

TOLOWER is a macro that uses a lookup table under the hood which is similar to llvm::tolower.

ruiu accepted this revision.Sep 15 2018, 4:45 PM

LGTM

Please add the description to the commit message.

This revision is now accepted and ready to land.Sep 15 2018, 4:45 PM
This revision was automatically updated to reflect the committed changes.