From aa33688cada423d987ce03ecbc13f2c554223d77 Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Wed, 26 Jan 2022 11:16:11 +0100 Subject: [PATCH] [llvm][support] Replace `std::vector` use in YAMLTraits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LLVM Programmer’s Manual strongly discourages the use of `std::vector` 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 --- llvm/include/llvm/Support/YAMLTraits.h | 3 ++- llvm/lib/Support/YAMLTraits.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) 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 @@ private: std::error_code EC; BumpPtrAllocator StringAllocator; document_iterator DocIterator; - std::vector 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(CurrentNode)) { - BitValuesUsed.insert(BitValuesUsed.begin(), SQ->Entries.size(), false); + BitValuesUsed.resize(SQ->Entries.size()); } else { setError(CurrentNode, "expected sequence of bit values"); }