Use unique_ptr in ir::context_impl (#462)

Co-authored-by: Philippe Tillet <Phil.Tillet@gmail.com>
This commit is contained in:
daadaada
2022-02-25 08:07:10 +08:00
committed by GitHub
parent 98ed7db8c1
commit d9dd97492f
4 changed files with 24 additions and 28 deletions

View File

@@ -47,10 +47,10 @@ constant_int *constant_int::get(type *ty, uint64_t value) {
if (!ty->is_integer_ty())
throw std::runtime_error("Cannot create constant_int with non integer ty");
context_impl *impl = ty->get_context().p_impl.get();
constant_int *& cst = impl->int_constants_[std::make_pair(ty, value)];
if(cst == nullptr)
cst = new constant_int(ty, value);
return cst;
std::unique_ptr<constant_int> &cst = impl->int_constants_[std::make_pair(ty, value)];
if(!cst)
cst.reset(new constant_int(ty, value));
return cst.get();
}
@@ -73,10 +73,10 @@ constant *constant_fp::get_zero_value_for_negation(type *ty) {
constant *constant_fp::get(type *ty, double v){
context_impl *impl = ty->get_context().p_impl.get();
constant_fp *&result = impl->fp_constants_[std::make_pair(ty, v)];
std::unique_ptr<constant_fp> &result = impl->fp_constants_[std::make_pair(ty, v)];
if(!result)
result = new constant_fp(ty, v);
return result;
result.reset(new constant_fp(ty, v));
return result.get();
}
@@ -86,10 +86,10 @@ undef_value::undef_value(type *ty)
undef_value *undef_value::get(type *ty) {
context_impl *impl = ty->get_context().p_impl.get();
undef_value *&result = impl->uv_constants_[ty];
std::unique_ptr<undef_value> &result = impl->uv_constants_[ty];
if(!result)
result = new undef_value(ty);
return result;
result.reset(new undef_value(ty));
return result.get();
}
/* global value */