llvm-project/lldb/unittests/Utility
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
..
Inputs Move StructuredData from Core to Utility 2017-06-27 10:45:31 +00:00
AnsiTerminalTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ArchSpecTest.cpp [Utility] Fix ArchSpec.MergeFrom to correctly merge environments 2019-02-27 00:47:39 +00:00
ArgsTest.cpp [Args] Handle backticks to prevent crash. 2019-03-25 17:27:14 +00:00
BroadcasterTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CMakeLists.txt Move RangeMap.h into Utility 2019-03-06 14:41:43 +00:00
CleanUpTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CompletionRequestTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ConstStringTest.cpp Allow direct comparison of ConstString against StringRef 2019-04-26 07:21:36 +00:00
DataExtractorTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
EnvironmentTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
EventTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
FileCollectorTest.cpp [test] Use correct macro in FileCollectorTest.cpp 2019-01-29 22:53:47 +00:00
FileSpecTest.cpp Breakpad: auto-detect path style of file entries 2019-02-11 14:11:00 +00:00
FlagsTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
JSONTest.cpp Fixup for r311483: Use correct path to StreamString.h 2017-08-22 19:09:39 +00:00
ListenerTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
LogTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
NameMatchesTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
OptionsWithRawTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
PredicateTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ProcessInfoTest.cpp Move ProcessInfo from Host to Utility. 2019-03-04 21:51:03 +00:00
RangeMapTest.cpp Move RangeMap.h into Utility 2019-03-06 14:41:43 +00:00
RangeTest.cpp Move RangeMap.h into Utility 2019-03-06 14:41:43 +00:00
RegisterValueTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ReproducerInstrumentationTest.cpp [Reproducers] Capture return values of functions returning by ptr/ref 2019-04-03 21:31:22 +00:00
ReproducerTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ScalarTest.cpp [unittest] Fix scalar unit test. 2019-01-31 18:48:17 +00:00
StateTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
StatusTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
StreamTeeTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
StreamTest.cpp [NFC] Remove ASCII lines from comments 2019-04-10 20:48:55 +00:00
StringExtractorTest.cpp unittests: Specify types in a bunch of unittest EXPECT's 2016-10-17 18:22:03 +00:00
StringLexerTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
StringListTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
StructuredDataTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
TildeExpressionResolverTest.cpp Revert "[FileSystem] Make use of FS in TildeExpressionResolver" 2018-11-09 01:59:28 +00:00
TimeoutTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
TimerTest.cpp [lldb] [unittests] Use non-empty format string for Timer() 2019-02-26 20:14:07 +00:00
UUIDTest.cpp Add UUID::SetFromOptionalStringRef, use it in DynamicLoaderDarwin 2019-01-24 22:43:44 +00:00
UriParserTest.cpp UriParser cleanup 2017-02-10 12:21:22 +00:00
UserIDResolverTest.cpp Refactor user/group name resolving code 2019-03-04 18:48:00 +00:00
VASprintfTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
VMRangeTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00