mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-28 02:11:43 +00:00
Use StringRef and ArrayRef return values when buf passed.
For functions where a SmallVector is passed to be used as a stack buffer for the return value, have the return value be the appropriate StringRef or ArrayRef type. This allows for both more natural usage and enables directly returning (rather than copying) a permanently stored or constant string.
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
#include "llvm/ArrayRef.h"
|
||||
#include "llvm/SmallVector.h"
|
||||
#include "support/atomic_static.h"
|
||||
|
||||
@@ -52,7 +53,7 @@ class UnlimitedHandleResource {
|
||||
void Free(THandle handle);
|
||||
|
||||
template <typename T>
|
||||
void GetAll(llvm::SmallVectorImpl<T>& handles);
|
||||
llvm::ArrayRef<T> GetAll(llvm::SmallVectorImpl<T>& vec);
|
||||
|
||||
private:
|
||||
THandle MakeHandle(size_t i) {
|
||||
@@ -124,13 +125,15 @@ void UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::Free(
|
||||
|
||||
template <typename THandle, typename TStruct, int typeValue, typename TMutex>
|
||||
template <typename T>
|
||||
void UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::GetAll(
|
||||
llvm::SmallVectorImpl<T>& handles) {
|
||||
llvm::ArrayRef<T>
|
||||
UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::GetAll(
|
||||
llvm::SmallVectorImpl<T>& vec) {
|
||||
std::lock_guard<TMutex> sync(m_handleMutex);
|
||||
size_t i;
|
||||
for (i = 0; i < m_structures.size(); i++) {
|
||||
if (m_structures[i] != nullptr) handles.push_back(MakeHandle(i));
|
||||
if (m_structures[i] != nullptr) vec.push_back(MakeHandle(i));
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
|
||||
template <typename THandle, typename TStruct, int typeValue,
|
||||
|
||||
Reference in New Issue
Block a user