Use a unique_ptr instead of manual deletion for PIMPL idiom (NFC)

PiperOrigin-RevId: 230930254
This commit is contained in:
Mehdi Amini 2019-01-25 10:51:51 -08:00 committed by jpienaar
parent ba1715f407
commit d9ce382fc9
2 changed files with 5 additions and 8 deletions

View File

@ -68,9 +68,8 @@ public:
llvm::Error invoke(StringRef name, Args &... args);
private:
// FIXME: we may want a `unique_ptr` here if impl::OrcJIT decides to provide
// a default constructor.
impl::OrcJIT *jit;
// Private implementation of the JIT (PIMPL)
std::unique_ptr<impl::OrcJIT> jit;
llvm::LLVMContext llvmContext;
};

View File

@ -257,10 +257,8 @@ void packFunctionArguments(llvm::Module *module) {
}
}
ExecutionEngine::~ExecutionEngine() {
if (jit)
delete jit;
}
// Out of line for PIMPL unique_ptr.
ExecutionEngine::~ExecutionEngine() = default;
Expected<std::unique_ptr<ExecutionEngine>> ExecutionEngine::create(Module *m) {
auto engine = llvm::make_unique<ExecutionEngine>();
@ -280,7 +278,7 @@ Expected<std::unique_ptr<ExecutionEngine>> ExecutionEngine::create(Module *m) {
setupTargetTriple(llvmModule.get());
packFunctionArguments(llvmModule.get());
engine->jit = std::move(*expectedJIT).release();
engine->jit = std::move(*expectedJIT);
if (auto err = engine->jit->addModule(std::move(llvmModule)))
return std::move(err);