[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
This commit is contained in:
Jan Svoboda 2022-01-26 11:16:11 +01:00
parent 24a49e99f3
commit aa33688cad
2 changed files with 3 additions and 2 deletions

View File

@ -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 @@ private:
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;

View File

@ -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");
}