Add a llvm::Split() implementation that can be used via range-for loop,
e.g.:
for (StringRef x : llvm::Split("foo,bar,baz", ',')) ...
The implementation uses an additional SplittingIterator class that
uses StringRef::split() internally.
Paths
| Differential D110496
[llvm] [ADT] Add a range/iterator-based Split() ClosedPublic Authored by mgorny on Sep 26 2021, 6:07 AM.
Details Summary Add a llvm::Split() implementation that can be used via range-for loop, for (StringRef x : llvm::Split("foo,bar,baz", ',')) ... The implementation uses an additional SplittingIterator class that
Diff Detail
Event Timeline
This revision is now accepted and ready to land.Sep 26 2021, 4:53 PM mgorny retitled this revision from [llvm] [ADT] Add a range/iterator-based split() to [llvm] [ADT] Add a range/iterator-based Split(). Comment ActionsAttempt to fix linter issues. This revision was landed with ongoing or failed builds.Sep 27 2021, 1:43 AM Closed by commit rGf4b71e3479bf: [llvm] [ADT] Add a range/iterator-based Split() (authored by mgorny). · Explain Why This revision was automatically updated to reflect the committed changes. Comment Actions I like it as well :)
Revision Contents
Diff 375168 lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
llvm/include/llvm/ADT/StringExtras.h
llvm/unittests/ADT/StringExtrasTest.cpp
|
This compares the contents of the StringRefs, while it should be comparing the pointers instead. I don't think it can cause correctness issues though I think it might be able to cause super-linear iteration complexity for some pathological inputs and more complex algorithms (a string consisting of many identical substrings, and an algorithm which compares two successive iterators).
Since comparing iterators from different sequences is UB, I think that comparing just Current.data() could actually suffice (the rest could be asserts) -- one has to be careful how he initializes the past-the-end iterator though.