mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[SIL] Extract reoccuring allocation patterns.
No need to write a pile of manual memcpy's.
This commit is contained in:
@@ -589,6 +589,22 @@ public:
|
||||
/// Allocate memory using the module's internal allocator.
|
||||
void *allocate(unsigned Size, unsigned Align) const;
|
||||
|
||||
template <typename T> T *allocate(unsigned Count) const {
|
||||
return static_cast<T *>(allocate(sizeof(T) * Count, alignof(T)));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
MutableArrayRef<T> allocateCopy(ArrayRef<T> Array) const {
|
||||
MutableArrayRef<T> result(allocate<T>(Array.size()), Array.size());
|
||||
std::uninitialized_copy(Array.begin(), Array.end(), result.begin());
|
||||
return result;
|
||||
}
|
||||
|
||||
StringRef allocateCopy(StringRef Str) const {
|
||||
auto result = allocateCopy<char>({Str.data(), Str.size()});
|
||||
return {result.data(), result.size()};
|
||||
}
|
||||
|
||||
/// Allocate memory for an instruction using the module's internal allocator.
|
||||
void *allocateInst(unsigned Size, unsigned Align) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user