[Lldb-commits] [PATCH] D61231: Add 'oneOf' utility function for comparing a ConstString against a set of strings
Pavel Labath via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Mon Apr 29 01:50:43 PDT 2019
labath added a comment.
In D61231#1481804 <https://reviews.llvm.org/D61231#1481804>, @teemperor wrote:
> Yeah, I'm also just like 60% confident that this more readable/expressive.
I'm about 70% against this ( :P ), and the main reason for that opinion is that there is nothing like this in llvm, and if llvm was able to get away without it, then I don't see why shouldn't we be able to do it too. The way these kinds of things are usually done in llvm is via the `StringSwitch` class, and it seems to me that `StringSwitch` could be directly used in at least half of the motivating use cases you show here (and in the rest, it could be used after a mild code refactor, which that code needs anyway).
(And yeah, I am aware that going through StringSwitch will mean we lose the fast string comparison that ConstString was meant to provide, but I am sure that this will have no impact on the overall performance here.)
================
Comment at: lldb/source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp:133-139
+ if (name.oneOf("ptr", "pointer"))
return 0;
- if (name == "del" || name == "deleter")
+ if (name.oneOf("del", "deleter"))
return 1;
- if (name == "obj" || name == "object" || name == "$$dereference$$")
+ if (name.oneOf("obj", "object", "$$dereference$$"))
return 2;
return UINT32_MAX;
----------------
This is a prime example for a `StringSwitch`, which is how these kinds of things are usually done in llvm.
```
return StringSwitch<size_t>(name.GetStringRef()).Cases("ptr, "pointer", 0).Cases("del", "deleter", 1).Cases("obj", "object", "$$dereference$$", 2).Default(UINT32_MAX);
```
(+ running clang-format over that)
================
Comment at: lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp:1039-1082
+ if (type_hint.oneOf(g_CFBag, g_CFBinaryHeap)) {
prefix = "@";
return true;
}
if (type_hint == g_NSNumberChar) {
prefix = "(char)";
----------------
Using StringSwitch would make this code around three times shorter.
Repository:
rLLDB LLDB
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61231/new/
https://reviews.llvm.org/D61231
More information about the lldb-commits
mailing list