Skip to content

Commit

Permalink
replace some lines with make_unique
Browse files Browse the repository at this point in the history
  • Loading branch information
kwkam committed Nov 8, 2017
1 parent 3c6a70c commit dd60bba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/HttpHeaderProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ HttpHeaderProcessor::HttpHeaderProcessor(ParserMode mode)
state_(mode == CLIENT_PARSER ? PREV_RES_VERSION : PREV_METHOD),
lastBytesProcessed_(0),
lastFieldHdKey_(HttpHeader::MAX_INTERESTING_HEADER),
result_(new HttpHeader())
result_(make_unique<HttpHeader>())
{
}

Expand Down Expand Up @@ -481,7 +481,7 @@ void HttpHeaderProcessor::clear()
buf_.clear();
lastFieldName_.clear();
lastFieldHdKey_ = HttpHeader::MAX_INTERESTING_HEADER;
result_.reset(new HttpHeader());
result_ = make_unique<HttpHeader>();
headers_.clear();
}

Expand Down
8 changes: 4 additions & 4 deletions src/bignum.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ template <size_t dim> class ulong {
std::unique_ptr<char_t[]> buf_;

public:
inline ulong() : buf_(new char_t[dim]()) {}
inline ulong(size_t t) : buf_(new char_t[dim]())
inline ulong() : buf_(make_unique<char_t[]>(dim)) {}
inline ulong(size_t t) : buf_(make_unique<char_t[]>(dim))
{
memcpy(buf_.get(), (char_t*)&t, sizeof(t));
}
inline ulong(const ulong<dim>& rhs) : buf_(new char_t[dim]())
inline ulong(const ulong<dim>& rhs) : buf_(make_unique<char_t[]>(dim))
{
memcpy(buf_.get(), rhs.buf_.get(), dim);
}
explicit inline ulong(const char_t* data, size_t size)
: buf_(new char_t[dim]())
: buf_(make_unique<char_t[]>(dim))
{
if (size > dim) {
throw std::bad_alloc();
Expand Down
12 changes: 6 additions & 6 deletions src/crypto_hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1055,22 +1055,22 @@ std::unique_ptr<Algorithm> crypto::hash::create(Algorithms algo)
{
switch (algo) {
case algoMD5:
return std::unique_ptr<MD5>(new MD5());
return make_unique<MD5>();

case algoSHA1:
return std::unique_ptr<SHA1>(new SHA1());
return make_unique<SHA1>();

case algoSHA224:
return std::unique_ptr<SHA224>(new SHA224());
return make_unique<SHA224>();

case algoSHA256:
return std::unique_ptr<SHA256>(new SHA256());
return make_unique<SHA256>();

case algoSHA384:
return std::unique_ptr<SHA384>(new SHA384());
return make_unique<SHA384>();

case algoSHA512:
return std::unique_ptr<SHA512>(new SHA512());
return make_unique<SHA512>();

default:
throw std::domain_error("Invalid hash algorithm");
Expand Down

0 comments on commit dd60bba

Please sign in to comment.