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

Jan Svoboda via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 25 01:23:22 PST 2022


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

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, false)`, which has the same sematnics but avoids using `insert` and iterators, which `llvm::BitVector` doesn't possess.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D118111

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


Index: llvm/lib/Support/YAMLTraits.cpp
===================================================================
--- llvm/lib/Support/YAMLTraits.cpp
+++ llvm/lib/Support/YAMLTraits.cpp
@@ -298,7 +298,7 @@
 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(), false);
   } else {
     setError(CurrentNode, "expected sequence of bit values");
   }
Index: llvm/include/llvm/Support/YAMLTraits.h
===================================================================
--- llvm/include/llvm/Support/YAMLTraits.h
+++ 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"
@@ -1519,7 +1520,7 @@
   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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118111.402794.patch
Type: text/x-patch
Size: 1388 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220125/4c4211c3/attachment.bin>


More information about the llvm-commits mailing list