llvm-project/lldb/unittests
Raphael Isemann 05cfdb0eac Allow direct comparison of ConstString against StringRef
Summary:
When we want to compare a ConstString against a string literal (or any other non-ConstString),
we currently have to explicitly turn the other string into a ConstString. This makes sense as
comparing ConstStrings against each other is only a fast pointer comparison.

However, currently we (rather incorrectly) use in several places in LLDB temporary ConstStrings when
we just want to compare a given ConstString against a hardcoded value, for example like this:
```
if (extension != ConstString(".oat") && extension != ConstString(".odex"))
```

Obviously this kind of defeats the point of ConstStrings. In the comparison above we would
construct two temporary ConstStrings every time we hit the given code. Constructing a
ConstString is relatively expensive: we need to go to the StringPool, take a read and possibly
an exclusive write-lock and then look up our temporary string in the string map of the pool.
So we do a lot of heavy work for essentially just comparing a <6 characters in two strings.

I initially wanted to just fix these issues by turning the temporary ConstString in static variables/
members, but that made the code much less readable. Instead I propose to add a new overload
for the ConstString comparison operator that takes a StringRef. This comparison operator directly
compares the ConstString content against the given StringRef without turning the StringRef into
a ConstString.

This means that the example above can look like this now:
```
if (extension != ".oat" && extension != ".odex")
```
It also no longer has to unlock/lock two locks and call multiple functions in other TUs for constructing
the temporary ConstString instances. Instead this should end up just being a direct string comparison
of the two given strings on most compilers.

This patch also directly updates all uses of temporary and short ConstStrings in LLDB to use this new
comparison operator. It also adds a some unit tests for the new and old comparison operator.

Reviewers: #lldb, JDevlieghere, espindola, amccarth

Reviewed By: JDevlieghere, amccarth

Subscribers: amccarth, clayborg, JDevlieghere, emaste, arichardson, MaskRay, lldb-commits

Tags: #lldb

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

llvm-svn: 359281
2019-04-26 07:21:36 +00:00
..
Breakpoint Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Core [LLDB] - Update the test cases after yaml2obj change. 2019-04-03 15:28:35 +00:00
Disassembler When disassembling Aarch64 target and vendor Apple, set the cpu to 2019-03-07 03:16:45 +00:00
Editline [EditLineTests] Call setenv() before editline is initialized. 2019-04-24 18:39:39 +00:00
Expression [ExpressionParser] Add swift-lldb case for finding clang resource dir 2019-03-26 21:00:42 +00:00
Host Clear the output string passed to GetHostName() 2019-04-17 03:13:06 +00:00
Interpreter [CMake] Only the Python scirpt interpreter should link against Python. 2019-04-01 22:03:04 +00:00
Language [NFC] Remove ASCII lines from comments 2019-04-10 20:48:55 +00:00
ObjectFile Breakpad: Match the new UUID algorithm in minidumps 2019-04-16 14:51:47 +00:00
Platform Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Process Minidump: yamlify module-related unit tests 2019-04-21 13:12:40 +00:00
ScriptInterpreter [CMake] Only the Python scirpt interpreter should link against Python. 2019-04-01 22:03:04 +00:00
Signals Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Symbol PostfixExpression: move parser out of NativePDB internals 2019-04-24 07:27:05 +00:00
SymbolFile [NFC] Fix license headers after r352845 2019-02-08 08:48:15 +00:00
Target Refactor user/group name resolving code 2019-03-04 18:48:00 +00:00
TestingSupport Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
UnwindAssembly Use std::make_shared in LLDB (NFC) 2019-02-11 23:13:08 +00:00
Utility Allow direct comparison of ConstString against StringRef 2019-04-26 07:21:36 +00:00
debugserver [NFC] Remove ASCII lines from comments 2019-04-10 20:48:55 +00:00
tools [lldb-mi] Check raw pointers before passing them to std::string ctor/assignment 2019-02-25 16:40:11 +00:00
CMakeLists.txt [CMake] Only test debugserver if platform can use debugserver 2019-01-18 00:05:25 +00:00
gtest_common.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00