replace some lines with make_unique

pull/1064/head
kwkam 2017-11-08 15:02:37 +08:00
parent 3c6a70c566
commit dd60bba5ad
3 changed files with 12 additions and 12 deletions

View File

@ -79,7 +79,7 @@ HttpHeaderProcessor::HttpHeaderProcessor(ParserMode mode)
state_(mode == CLIENT_PARSER ? PREV_RES_VERSION : PREV_METHOD), state_(mode == CLIENT_PARSER ? PREV_RES_VERSION : PREV_METHOD),
lastBytesProcessed_(0), lastBytesProcessed_(0),
lastFieldHdKey_(HttpHeader::MAX_INTERESTING_HEADER), lastFieldHdKey_(HttpHeader::MAX_INTERESTING_HEADER),
result_(new HttpHeader()) result_(make_unique<HttpHeader>())
{ {
} }
@ -481,7 +481,7 @@ void HttpHeaderProcessor::clear()
buf_.clear(); buf_.clear();
lastFieldName_.clear(); lastFieldName_.clear();
lastFieldHdKey_ = HttpHeader::MAX_INTERESTING_HEADER; lastFieldHdKey_ = HttpHeader::MAX_INTERESTING_HEADER;
result_.reset(new HttpHeader()); result_ = make_unique<HttpHeader>();
headers_.clear(); headers_.clear();
} }

View File

@ -31,17 +31,17 @@ private:
std::unique_ptr<char_t[]> buf_; std::unique_ptr<char_t[]> buf_;
public: public:
inline ulong() : buf_(new char_t[dim]()) {} inline ulong() : buf_(make_unique<char_t[]>(dim)) {}
inline ulong(size_t t) : buf_(new char_t[dim]()) inline ulong(size_t t) : buf_(make_unique<char_t[]>(dim))
{ {
memcpy(buf_.get(), (char_t*)&t, sizeof(t)); 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); memcpy(buf_.get(), rhs.buf_.get(), dim);
} }
explicit inline ulong(const char_t* data, size_t size) explicit inline ulong(const char_t* data, size_t size)
: buf_(new char_t[dim]()) : buf_(make_unique<char_t[]>(dim))
{ {
if (size > dim) { if (size > dim) {
throw std::bad_alloc(); throw std::bad_alloc();

View File

@ -1055,22 +1055,22 @@ std::unique_ptr<Algorithm> crypto::hash::create(Algorithms algo)
{ {
switch (algo) { switch (algo) {
case algoMD5: case algoMD5:
return std::unique_ptr<MD5>(new MD5()); return make_unique<MD5>();
case algoSHA1: case algoSHA1:
return std::unique_ptr<SHA1>(new SHA1()); return make_unique<SHA1>();
case algoSHA224: case algoSHA224:
return std::unique_ptr<SHA224>(new SHA224()); return make_unique<SHA224>();
case algoSHA256: case algoSHA256:
return std::unique_ptr<SHA256>(new SHA256()); return make_unique<SHA256>();
case algoSHA384: case algoSHA384:
return std::unique_ptr<SHA384>(new SHA384()); return make_unique<SHA384>();
case algoSHA512: case algoSHA512:
return std::unique_ptr<SHA512>(new SHA512()); return make_unique<SHA512>();
default: default:
throw std::domain_error("Invalid hash algorithm"); throw std::domain_error("Invalid hash algorithm");