|
| 1 | +//===--- SmallPtrSetVector.h ----------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#ifndef SWIFT_BASIC_SMALLPTRSETVECTOR_H |
| 14 | +#define SWIFT_BASIC_SMALLPTRSETVECTOR_H |
| 15 | + |
| 16 | +#include "swift/Basic/LLVM.h" |
| 17 | +#include "llvm/ADT/SetVector.h" |
| 18 | +#include "llvm/ADT/SmallPtrSet.h" |
| 19 | +#include "llvm/ADT/SmallVector.h" |
| 20 | + |
| 21 | +namespace swift { |
| 22 | + |
| 23 | +/// A SetVector that performs no allocations if smaller than a certain |
| 24 | +/// size. Uses a SmallPtrSet/SmallVector internally. |
| 25 | +template <typename T, unsigned VectorSize, unsigned SetSize = VectorSize> |
| 26 | +class SmallPtrSetVector : public llvm::SetVector<T, SmallVector<T, VectorSize>, |
| 27 | + SmallPtrSet<T, SetSize>> { |
| 28 | +public: |
| 29 | + SmallPtrSetVector() = default; |
| 30 | + |
| 31 | + /// Initialize a SmallPtrSetVector with a range of elements |
| 32 | + template <typename It> SmallPtrSetVector(It Start, It End) { |
| 33 | + this->insert(Start, End); |
| 34 | + } |
| 35 | +}; |
| 36 | + |
| 37 | +} // namespace swift |
| 38 | + |
| 39 | +namespace std { |
| 40 | + |
| 41 | +/// Implement std::swap in terms of SmallSetVector swap. |
| 42 | +/// |
| 43 | +/// This matches llvm's implementation for SmallSetVector. |
| 44 | +template <typename T, unsigned VectorSize, unsigned SetSize = VectorSize> |
| 45 | +inline void swap(swift::SmallPtrSetVector<T, VectorSize, SetSize> &LHS, |
| 46 | + swift::SmallPtrSetVector<T, VectorSize, SetSize> &RHS) { |
| 47 | + LHS.swap(RHS); |
| 48 | +} |
| 49 | + |
| 50 | +} // end namespace std |
| 51 | + |
| 52 | +#endif |
0 commit comments