Skip to content

Commit c6cc09b

Browse files
committed
Simplify PointsToSetOwner; TODO: Get rid of storing the PTS pointer twice
1 parent 7f309ab commit c6cc09b

1 file changed

Lines changed: 6 additions & 23 deletions

File tree

include/phasar/PhasarLLVM/Pointer/PointsToSetOwner.h

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,19 @@ template <typename PointsToSetTy> class PointsToSetOwner {
1919
public:
2020
explicit PointsToSetOwner() = default;
2121
explicit PointsToSetOwner(size_t InitialCapacity) {
22-
Owner.reserve(InitialCapacity);
2322
OwnedPTS.reserve(InitialCapacity);
2423
}
2524

2625
PointsToSetTy *acquire() {
27-
Owner.push_back(std::make_unique<PointsToSetTy>());
28-
OwnedPTS[Owner.back().get()] = Owner.size() - 1;
29-
return Owner.back().get();
30-
}
31-
void release(PointsToSetTy *PTS) {
32-
if (Owner.empty()) {
33-
return;
34-
}
35-
36-
assert(Owner.size() == OwnedPTS.size());
37-
38-
if (auto It = OwnedPTS.find(PTS); It != OwnedPTS.end()) {
39-
auto Idx = It->second;
40-
41-
OwnedPTS[Owner.back().get()] = Idx;
42-
OwnedPTS.erase(PTS);
43-
44-
std::swap(Owner[Idx], Owner.back());
45-
Owner.pop_back();
46-
}
26+
auto Ptr = std::make_unique<PointsToSetTy>();
27+
auto Ret = Ptr.get();
28+
OwnedPTS.try_emplace(Ret, std::move(Ptr));
29+
return Ret;
4730
}
31+
void release(PointsToSetTy *PTS) { OwnedPTS.erase(PTS); }
4832

4933
private:
50-
std::vector<std::unique_ptr<PointsToSetTy>> Owner;
51-
llvm::DenseMap<PointsToSetTy *, size_t> OwnedPTS;
34+
llvm::DenseMap<PointsToSetTy *, std::unique_ptr<PointsToSetTy>> OwnedPTS;
5235
};
5336
} // namespace psr
5437

0 commit comments

Comments
 (0)