[PATCH] D102599: [ADT] Remove StringRef::withNullAsEmpty

Raphael Isemann via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 17 01:05:37 PDT 2021


totally_not_teemperor created this revision.
Herald added a subscriber: dexonsmith.
totally_not_teemperor requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

A long time ago LLDB wanted to start using StringRef instead of
C-Strings/ConstString but was blocked by the StringRef(const char *) ctor
asserting that the C-string isn't a nullptr. To workaround this, D24697 <https://reviews.llvm.org/D24697>
introduced a special function called withNullAsEmpty and that's what LLDB (and
only LLDB) started to use to build StringRefs from C-strings.

A bit later it seems that withNullAsEmpty was declared too awkward to use and
instead the assert in the StringRef constructor got removed (see D24904 <https://reviews.llvm.org/D24904>). The
rest of LLDB was then converted to StringRef by just calling the now perfectly
usable implicit constructor.

However, it seems that the original approach with withNullAsEmpty was never
touched again since then and now just exists as afunction in StringRef that
is only used in a few places in LLDB.

I removed the few uses of withNullAsEmpty in D102597 <https://reviews.llvm.org/D102597> and this patch removes
the function itself. Calling the implicit StringRef(const char *) constructor
is the preferred way of doing this today.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102599

Files:
  llvm/include/llvm/ADT/StringRef.h


Index: llvm/include/llvm/ADT/StringRef.h
===================================================================
--- llvm/include/llvm/ADT/StringRef.h
+++ llvm/include/llvm/ADT/StringRef.h
@@ -120,10 +120,6 @@
         : Data(Str.data()), Length(Str.size()) {}
 #endif
 
-    static StringRef withNullAsEmpty(const char *data) {
-      return StringRef(data ? data : "");
-    }
-
     /// @}
     /// @name Iterators
     /// @{


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102599.345781.patch
Type: text/x-patch
Size: 426 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210517/8f3c1be0/attachment.bin>


More information about the llvm-commits mailing list