[lld] r342342 - [ELF] Use llvm::toLower instead of libc call tolower

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 15 16:59:13 PDT 2018


Author: maskray
Date: Sat Sep 15 16:59:13 2018
New Revision: 342342

URL: http://llvm.org/viewvc/llvm-project?rev=342342&view=rev
Log:
[ELF] Use llvm::toLower instead of libc call tolower

tolower() has some overhead because current locale is considered (though in lld the default "C" locale is used which does not matter too much). 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.

Disregarding locale also matches gdb's behavior (gdb/minsyms.h):

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

where TOLOWER (include/safe-ctype.h) is a macro that uses a lookup table under the hood which is similar to llvm::toLower.

Reviewers: ruiu, espindola

Subscribers: emaste, arichardson, llvm-commits

Differential Revision: https://reviews.llvm.org/D52128

Modified:
    lld/trunk/ELF/SyntheticSections.cpp

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=342342&r1=342341&r2=342342&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Sat Sep 15 16:59:13 2018
@@ -30,6 +30,7 @@
 #include "lld/Common/Threads.h"
 #include "lld/Common/Version.h"
 #include "llvm/ADT/SetOperations.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h"
 #include "llvm/Object/Decompressor.h"
@@ -2338,7 +2339,7 @@ unsigned PltSection::getPltRelocOff() co
 static uint32_t computeGdbHash(StringRef S) {
   uint32_t H = 0;
   for (uint8_t C : S)
-    H = H * 67 + tolower(C) - 113;
+    H = H * 67 + toLower(C) - 113;
   return H;
 }
 




More information about the llvm-commits mailing list