Skip to content

Commit

Permalink
AllocatedCXCodeCompleteResults::DiagnosticWrappers: use unique_ptr to…
Browse files Browse the repository at this point in the history
… simplify memory management
  • Loading branch information
dwblaikie committed Apr 29, 2020
1 parent f6d5320 commit c98a7e9
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions clang/tools/libclang/CIndexCodeCompletion.cpp
Expand Up @@ -254,7 +254,7 @@ struct AllocatedCXCodeCompleteResults : public CXCodeCompleteResults {
SmallVector<StoredDiagnostic, 8> Diagnostics;

/// Allocated API-exposed wrappters for Diagnostics.
SmallVector<CXStoredDiagnostic *, 8> DiagnosticsWrappers;
SmallVector<std::unique_ptr<CXStoredDiagnostic>, 8> DiagnosticsWrappers;

IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;

Expand Down Expand Up @@ -371,7 +371,6 @@ AllocatedCXCodeCompleteResults::AllocatedCXCodeCompleteResults(
}

AllocatedCXCodeCompleteResults::~AllocatedCXCodeCompleteResults() {
llvm::DeleteContainerPointers(DiagnosticsWrappers);
delete [] Results;

for (unsigned I = 0, N = TemporaryBuffers.size(); I != N; ++I)
Expand Down Expand Up @@ -914,10 +913,12 @@ clang_codeCompleteGetDiagnostic(CXCodeCompleteResults *ResultsIn,
if (!Results || Index >= Results->Diagnostics.size())
return nullptr;

CXStoredDiagnostic *Diag = Results->DiagnosticsWrappers[Index];
CXStoredDiagnostic *Diag = Results->DiagnosticsWrappers[Index].get();
if (!Diag)
Results->DiagnosticsWrappers[Index] = Diag =
new CXStoredDiagnostic(Results->Diagnostics[Index], Results->LangOpts);
Diag = (Results->DiagnosticsWrappers[Index] =
std::make_unique<CXStoredDiagnostic>(
Results->Diagnostics[Index], Results->LangOpts))
.get();
return Diag;
}

Expand Down

0 comments on commit c98a7e9

Please sign in to comment.