Skip to content

Commit 172c281

Browse files
authored
[clang][bytecode] Use a SmallVector for EvalEmitter's locals (llvm#140513)
The offset we return for them are just indices, so we can use a vector here.
1 parent 3a86e0b commit 172c281

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

clang/lib/AST/ByteCode/EvalEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ EvalEmitter::EvalEmitter(Context &Ctx, Program &P, State &Parent,
2020
: Ctx(Ctx), P(P), S(Parent, P, Stk, Ctx, this), EvalResult(&Ctx) {}
2121

2222
EvalEmitter::~EvalEmitter() {
23-
for (auto &[K, V] : Locals) {
23+
for (auto &V : Locals) {
2424
Block *B = reinterpret_cast<Block *>(V.get());
2525
if (B->isInitialized())
2626
B->invokeDtor();
@@ -112,7 +112,7 @@ Scope::Local EvalEmitter::createLocal(Descriptor *D) {
112112

113113
// Register the local.
114114
unsigned Off = Locals.size();
115-
Locals.insert({Off, std::move(Memory)});
115+
Locals.push_back(std::move(Memory));
116116
return {Off, D};
117117
}
118118

clang/lib/AST/ByteCode/EvalEmitter.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,11 @@ class EvalEmitter : public SourceMapper {
111111
std::optional<PtrCallback> PtrCB;
112112

113113
/// Temporaries which require storage.
114-
llvm::DenseMap<unsigned, std::unique_ptr<char[]>> Locals;
114+
llvm::SmallVector<std::unique_ptr<char[]>> Locals;
115115

116116
Block *getLocal(unsigned Index) const {
117-
auto It = Locals.find(Index);
118-
assert(It != Locals.end() && "Missing local variable");
119-
return reinterpret_cast<Block *>(It->second.get());
117+
assert(Index < Locals.size());
118+
return reinterpret_cast<Block *>(Locals[Index].get());
120119
}
121120

122121
void updateGlobalTemporaries();

0 commit comments

Comments
 (0)