[demangler] Buffer peeking needs buffer
authorNathan Sidwell <nathan@acm.org>
Mon, 28 Mar 2022 19:38:48 +0000 (12:38 -0700)
committerNathan Sidwell <nathan@acm.org>
Mon, 9 May 2022 11:17:22 +0000 (04:17 -0700)
The output buffer has a 'back' member, which returns NUL when you try
it with an empty buffer.  But there are no use cases that need that
additional functionality.  This makes the 'back' member behave more
like STL containers' back members.  (It still returns a value, not a
reference.)

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D123201

libcxxabi/src/demangle/Utility.h
llvm/include/llvm/Demangle/Utility.h

index 6e0fa38..db19dca 100644 (file)
@@ -171,7 +171,8 @@ public:
   void setCurrentPosition(size_t NewPos) { CurrentPosition = NewPos; }
 
   char back() const {
-    return CurrentPosition ? Buffer[CurrentPosition - 1] : '\0';
+    assert(CurrentPosition);
+    return Buffer[CurrentPosition - 1];
   }
 
   bool empty() const { return CurrentPosition == 0; }
index b17eadc..ca7e44b 100644 (file)
@@ -171,7 +171,8 @@ public:
   void setCurrentPosition(size_t NewPos) { CurrentPosition = NewPos; }
 
   char back() const {
-    return CurrentPosition ? Buffer[CurrentPosition - 1] : '\0';
+    assert(CurrentPosition);
+    return Buffer[CurrentPosition - 1];
   }
 
   bool empty() const { return CurrentPosition == 0; }