llvm-project/lldb
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
..
cmake [CMake] Remove Apple-specific version logic. 2019-04-17 18:23:22 +00:00
docs [Docs] Add more redirects 2019-04-24 01:58:17 +00:00
examples [Python] Simplify the code. NFCI. 2019-04-18 23:24:54 +00:00
include/lldb Allow direct comparison of ConstString against StringRef 2019-04-26 07:21:36 +00:00
lit [lldb] [lit] Use constexpr and better constraints in Register tests 2019-04-25 19:56:54 +00:00
lldb.xcodeproj add postfixexpression.cpp. 2019-04-24 19:50:53 +00:00
lldb.xcworkspace Remove accidentally commited file in xcshareddata 2019-02-05 23:35:01 +00:00
packages/Python/lldbsuite [TestTemplateFunction] Add a missing debug info variant. 2019-04-25 22:53:10 +00:00
resources [CMake] Revised LLDB.framework builds 2019-01-04 12:46:50 +00:00
scripts Kill modify-python-lldb.py 2019-04-24 13:23:19 +00:00
source Allow direct comparison of ConstString against StringRef 2019-04-26 07:21:36 +00:00
test [CMake] Make lldb-test-deps a dependency of check-lldb 2019-02-13 20:51:13 +00:00
third_party/Python/module [lldb/thirdparty] Remove unneeded files, asked by Jonas. 2019-03-12 20:41:36 +00:00
tools [tools] Only build lldb-test when needed. 2019-04-16 21:56:07 +00:00
unittests Allow direct comparison of ConstString against StringRef 2019-04-26 07:21:36 +00:00
utils [lldb-dotest] Print dotest.py invocation. 2019-04-03 01:26:38 +00:00
www Don't abort() in lldb_assert and document why. 2019-03-29 16:12:27 +00:00
.arcconfig
.clang-format
.gitignore Add .noindex to the gitignore 2019-04-05 17:57:42 +00:00
CMakeLists.txt [Cmake] Add missing dependency for running tests. 2019-04-17 23:43:01 +00:00
CODE_OWNERS.txt Fix/unify the spelling of Objective-C. 2018-06-13 16:21:24 +00:00
INSTALL.txt Changed builld-llvm.py to use .json files 2017-02-23 02:21:34 +00:00
LICENSE.TXT Fix typos throughout the license files that somehow I and my reviewers 2019-01-21 09:52:34 +00:00
use_lldb_suite_root.py