Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions clang/tools/libclang/CXString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,28 @@ CXString createCXString(CXStringBuf *buf) {
return Str;
}

CXStringSet *createSet(const std::vector<std::string> &Strings) {
template <typename StringTy, bool Copy>
static CXStringSet *createSetImpl(ArrayRef<StringTy> Strings) {
CXStringSet *Set = new CXStringSet;
Set->Count = Strings.size();
Set->Strings = new CXString[Set->Count];
for (unsigned SI = 0, SE = Set->Count; SI < SE; ++SI)
Set->Strings[SI] = createDup(Strings[SI]);
for (unsigned SI = 0, SE = Set->Count; SI < SE; ++SI) {
if constexpr (Copy) {
Set->Strings[SI] = createDup(Strings[SI]);
} else {
Set->Strings[SI] = createRef(Strings[SI]);
}
}
return Set;
}

CXStringSet *createSet(const std::vector<std::string> &Strings) {
return createSetImpl<std::string, true>(ArrayRef<std::string>(Strings));
}

CXStringSet *createRefSet(ArrayRef<StringRef> Strings) {
return createSetImpl<StringRef, false>(Strings);
}

//===----------------------------------------------------------------------===//
// String pools.
Expand Down
7 changes: 6 additions & 1 deletion clang/tools/libclang/CXString.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,14 @@ CXString createRef(std::string String) = delete;
/// Create a CXString object that is backed by a string buffer.
CXString createCXString(CXStringBuf *buf);

/// Create a CXStringSet object that owns the strings. Such an object should be
/// disposed with clang_disposeStringSet.
CXStringSet *createSet(const std::vector<std::string> &Strings);

/// Create a CXStringSet object that does not own the strings. Such an object
/// should still be disposed with clang_disposeStringSet.
CXStringSet *createRefSet(ArrayRef<StringRef> Strings);

/// A string pool used for fast allocation/deallocation of strings.
class CXStringPool {
public:
Expand Down Expand Up @@ -105,4 +111,3 @@ static inline StringRef getContents(const CXUnsavedFile &UF) {
}

#endif

Loading