From c32c5bf44ba65ef7e1e25070ddf4009a90b9377c Mon Sep 17 00:00:00 2001 From: an-tao <20741618@qq.com> Date: Thu, 31 May 2018 15:56:27 +0800 Subject: [PATCH] delete 'delete' operator --- lib/src/HttpAppFramework.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/src/HttpAppFramework.cc b/lib/src/HttpAppFramework.cc index 2f41a786..593fe0af 100755 --- a/lib/src/HttpAppFramework.cc +++ b/lib/src/HttpAppFramework.cc @@ -244,7 +244,6 @@ void HttpAppFrameworkImpl::onAsyncRequest(const HttpRequest& req,std::functionaddCookie("JSESSIONID",session_id); callback(*res); - // } } @@ -291,18 +290,17 @@ void HttpAppFrameworkImpl::readSendFile(const std::string& filePath,const HttpRe std::streambuf * pbuf = infile.rdbuf(); std::streamsize size = pbuf->pubseekoff(0,infile.end); pbuf->pubseekoff(0,infile.beg); // rewind - char *contents = new char [size]; - pbuf->sgetn (contents,size); + + std::string str; + str.reserve(size); + pbuf->sgetn (&str[0],size); + str.resize(size); infile.close(); - std::string str(contents,size); - - - resp->setStatusCode(HttpResponse::k200Ok); LOG_INFO << "file len:" << str.length(); - resp->setBody(str); - delete [] contents; + resp->setBody(std::move(str)); + } std::string HttpAppFrameworkImpl::getUuid()