Skip to content

Commit b2e2b85

Browse files
committed
[NFC] Pull CleanupBuffer up to DiverseStack
1 parent d1089c3 commit b2e2b85

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

include/swift/Basic/DiverseStack.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define SWIFT_BASIC_DIVERSESTACK_H
2424

2525
#include "swift/Basic/Malloc.h"
26+
#include "llvm/ADT/SmallVector.h"
2627
#include "llvm/Support/PointerLikeTypeTraits.h"
2728
#include <cassert>
2829
#include <cstring>
@@ -377,6 +378,22 @@ template <class T> class DiverseStackImpl : private DiverseStackBase {
377378
}
378379
};
379380

381+
/// A helper class for copying value off a DiverseStack.
382+
template <class T>
383+
class DiverseValueBuffer {
384+
llvm::SmallVector<char, sizeof(T) + 10 * sizeof(void*)> data;
385+
386+
public:
387+
DiverseValueBuffer(const T &value) {
388+
size_t size = value.allocated_size();
389+
data.reserve(size);
390+
data.set_size(size);
391+
memcpy(data.data(), reinterpret_cast<const void *>(&value), size);
392+
}
393+
394+
T &getCopy() { return *reinterpret_cast<T *>(data.data()); }
395+
};
396+
380397
} // end namespace swift
381398

382399
/// Allow stable_iterators to be put in things like TinyPtrVectors.

lib/SILGen/Cleanup.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,6 @@ static bool hasAnyActiveCleanups(DiverseStackImpl<Cleanup>::iterator begin,
5353
return false;
5454
}
5555

56-
namespace {
57-
/// A CleanupBuffer is a location to which to temporarily copy a
58-
/// cleanup.
59-
class CleanupBuffer {
60-
SmallVector<char, sizeof(Cleanup) + 10 * sizeof(void *)> data;
61-
62-
public:
63-
CleanupBuffer(const Cleanup &cleanup) {
64-
size_t size = cleanup.allocated_size();
65-
data.reserve(size);
66-
data.set_size(size);
67-
memcpy(data.data(), reinterpret_cast<const void *>(&cleanup), size);
68-
}
69-
70-
Cleanup &getCopy() { return *reinterpret_cast<Cleanup *>(data.data()); }
71-
};
72-
} // end anonymous namespace
73-
7456
void CleanupManager::popTopDeadCleanups() {
7557
auto end = (innermostScope ? innermostScope->depth : stack.stable_end());
7658
assert(end.isValid());
@@ -83,6 +65,8 @@ void CleanupManager::popTopDeadCleanups() {
8365
}
8466
}
8567

68+
using CleanupBuffer = DiverseValueBuffer<Cleanup>;
69+
8670
void CleanupManager::popAndEmitCleanup(CleanupHandle handle,
8771
CleanupLocation loc,
8872
ForUnwind_t forUnwind) {

0 commit comments

Comments
 (0)