[llvm] aa33688 - [llvm][support] Replace `std::vector<bool>` use in YAMLTraits

Jan Svoboda via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 26 02:20:22 PST 2022


Author: Jan Svoboda
Date: 2022-01-26T11:20:18+01:00
New Revision: aa33688cada423d987ce03ecbc13f2c554223d77

URL: https://github.com/llvm/llvm-project/commit/aa33688cada423d987ce03ecbc13f2c554223d77
DIFF: https://github.com/llvm/llvm-project/commit/aa33688cada423d987ce03ecbc13f2c554223d77.diff

LOG: [llvm][support] Replace `std::vector<bool>` use in YAMLTraits

LLVM Programmer’s Manual strongly discourages the use of `std::vector<bool>` and suggests `llvm::BitVector` as a possible replacement.

This patch replaces the use of `std::vector` with `llvm::BitVector` in LLVM's YAML traits and replaces the call to `Vec.insert(Vec.begin(), N, false)` on empty `Vec` with `Vec.resize(N)`, which has the same semantics but avoids using `insert` and iterators, which `llvm::BitVector` doesn't possess.

Reviewed By: dexonsmith, dblaikie

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

Added: 
    

Modified: 
    llvm/include/llvm/Support/YAMLTraits.h
    llvm/lib/Support/YAMLTraits.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h
index b7e41f662810..7ad73543fc6e 100644
--- a/llvm/include/llvm/Support/YAMLTraits.h
+++ b/llvm/include/llvm/Support/YAMLTraits.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_SUPPORT_YAMLTRAITS_H
 #define LLVM_SUPPORT_YAMLTRAITS_H
 
+#include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
@@ -1521,7 +1522,7 @@ class Input : public IO {
   std::error_code                     EC;
   BumpPtrAllocator                    StringAllocator;
   document_iterator                   DocIterator;
-  std::vector<bool>                   BitValuesUsed;
+  llvm::BitVector                     BitValuesUsed;
   HNode *CurrentNode = nullptr;
   bool                                ScalarMatchFound = false;
   bool AllowUnknownKeys = false;

diff  --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp
index 939427d3fc81..8cdd03149bcf 100644
--- a/llvm/lib/Support/YAMLTraits.cpp
+++ b/llvm/lib/Support/YAMLTraits.cpp
@@ -299,7 +299,7 @@ void Input::endEnumScalar() {
 bool Input::beginBitSetScalar(bool &DoClear) {
   BitValuesUsed.clear();
   if (SequenceHNode *SQ = dyn_cast<SequenceHNode>(CurrentNode)) {
-    BitValuesUsed.insert(BitValuesUsed.begin(), SQ->Entries.size(), false);
+    BitValuesUsed.resize(SQ->Entries.size());
   } else {
     setError(CurrentNode, "expected sequence of bit values");
   }


        


More information about the llvm-commits mailing list