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

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 15 16:30:50 PDT 2018


MaskRay added a comment.

In https://reviews.llvm.org/D52128#1235891, @ruiu wrote:

> 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 at 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`.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D52128





More information about the llvm-commits mailing list