[Lldb-commits] [lldb] [lldb] Check for abstract methods implementation in Scripted Plugin Objects (PR #71260)

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Fri Nov 3 18:08:52 PDT 2023


================
@@ -663,6 +663,18 @@ bool PythonDictionary::Check(PyObject *py_obj) {
   return PyDict_Check(py_obj);
 }
 
+bool PythonDictionary::HasKey(const llvm::Twine &key) const {
+  if (!IsValid())
+    return false;
+  PythonString key_object(key.str().data());
----------------
bulbazord wrote:

`key.str()` gives you a `std::string`, `PythonString`'s constructor takes a `StringRef`. If you pass it `key.str().data()` you're building a `StringRef` from a `const char *` which means you need to do some form of `strlen`. You can construct a `StringRef` from a `std::string` directly without a `strlen`.
Assuming you don't change `key` to a `StringRef`, you can do this and save yourself from some complexity.
```suggestion
  PythonString key_object(key.str());

https://github.com/llvm/llvm-project/pull/71260


More information about the lldb-commits mailing list