Modify something to improve performance

This commit is contained in:
antao 2018-12-24 15:06:05 +08:00
parent e69697466d
commit fb5bbde277
13 changed files with 33 additions and 31 deletions

View File

@ -118,7 +118,7 @@ class HttpResponse
virtual void setContentTypeCode(uint8_t type) = 0; virtual void setContentTypeCode(uint8_t type) = 0;
virtual void setContentTypeCodeAndCharacterSet(uint8_t type, const std::string charSet = "utf-8") = 0; virtual void setContentTypeCodeAndCharacterSet(uint8_t type, const std::string &charSet = "utf-8") = 0;
virtual uint8_t getContentTypeCode() = 0; virtual uint8_t getContentTypeCode() = 0;

View File

@ -221,7 +221,6 @@ const std::string HttpFile::getMd5() const
MD5_Final(md5, &c); MD5_Final(md5, &c);
return binaryStringToHex(md5, 16); return binaryStringToHex(md5, 16);
#else #else
Md5Encode encode; return Md5Encode::encode(_fileContent);
return encode.Encode(_fileContent);
#endif #endif
} }

View File

@ -76,7 +76,7 @@ class HttpResponseImpl : public HttpResponse
setContentType(web_content_type_to_string(type)); setContentType(web_content_type_to_string(type));
} }
virtual void setContentTypeCodeAndCharacterSet(uint8_t type, const std::string charSet = "utf-8") override virtual void setContentTypeCodeAndCharacterSet(uint8_t type, const std::string &charSet = "utf-8") override
{ {
_contentType = type; _contentType = type;
setContentType(web_content_type_and_charset_to_string(type, charSet)); setContentType(web_content_type_and_charset_to_string(type, charSet));

View File

@ -208,7 +208,7 @@ void HttpServerContext::pushRquestToPipeLine(const HttpRequestPtr &req)
} }
HttpRequestPtr HttpServerContext::getFirstRequest() const HttpRequestPtr HttpServerContext::getFirstRequest() const
{ {
if (_requestPipeLine.size() > 0) if (!_requestPipeLine.empty())
{ {
return _requestPipeLine.front().first; return _requestPipeLine.front().first;
} }
@ -216,7 +216,7 @@ HttpRequestPtr HttpServerContext::getFirstRequest() const
} }
HttpResponsePtr HttpServerContext::getFirstResponse() const HttpResponsePtr HttpServerContext::getFirstResponse() const
{ {
if (_requestPipeLine.size() > 0) if (!_requestPipeLine.empty())
{ {
return _requestPipeLine.front().second; return _requestPipeLine.front().second;
} }

View File

@ -231,7 +231,7 @@ std::string Md5Encode::GetHexStr(unsigned int num_str)
// function: Encode // function: Encode
// @param src_info:要加密的信息 // @param src_info:要加密的信息
// return :加密后的MD5值 // return :加密后的MD5值
std::string Md5Encode::Encode(std::string src_info) std::string Md5Encode::encode(const std::string &src_info)
{ {
ParamDynamic param; ParamDynamic param;
param.ua_ = kA; param.ua_ = kA;
@ -244,9 +244,8 @@ std::string Md5Encode::Encode(std::string src_info)
param.vd_last_ = kD; param.vd_last_ = kD;
std::string result; std::string result;
const char *src_data = src_info.c_str();
char *out_data_ptr = NULL; char *out_data_ptr = NULL;
int total_byte = FillData(src_data, strlen(src_data), &out_data_ptr); int total_byte = FillData(src_info.c_str(), src_info.length(), &out_data_ptr);
//char * data_BIT_OF_GROUP = out_data_ptr; //char * data_BIT_OF_GROUP = out_data_ptr;
for (int i = 0; i < total_byte / (BIT_OF_GROUP / BIT_OF_BYTE); ++i) for (int i = 0; i < total_byte / (BIT_OF_GROUP / BIT_OF_BYTE); ++i)
{ {

View File

@ -60,20 +60,18 @@ class Md5Encode
}; };
public: public:
Md5Encode()
{ static std::string encode(const std::string &src_info);
}
std::string Encode(std::string src_info);
protected: protected:
UInt32 CycleMoveLeft(UInt32 src_num, int bit_num_to_move); static UInt32 CycleMoveLeft(UInt32 src_num, int bit_num_to_move);
UInt32 FillData(const char *in_data_ptr, int data_byte_len, char **out_data_ptr); static void RoundF(char *data_512_ptr, ParamDynamic &param);
void RoundF(char *data_512_ptr, ParamDynamic &param); static void RoundG(char *data_512_ptr, ParamDynamic &param);
void RoundG(char *data_512_ptr, ParamDynamic &param); static void RoundH(char *data_512_ptr, ParamDynamic &param);
void RoundH(char *data_512_ptr, ParamDynamic &param); static void RoundI(char *data_512_ptr, ParamDynamic &param);
void RoundI(char *data_512_ptr, ParamDynamic &param); static void RotationCalculate(char *data_512_ptr, ParamDynamic &param);
void RotationCalculate(char *data_512_ptr, ParamDynamic &param); static std::string GetHexStr(unsigned int num_str);
std::string GetHexStr(unsigned int num_str); static UInt32 FillData(const char *in_data_ptr, int data_byte_len, char **out_data_ptr);
private: private:
// 幻数定义 // 幻数定义

View File

@ -7,4 +7,4 @@ add_executable(class_name_test ClassNameTest.cc)
add_executable(sha1_test Sha1Test.cc) add_executable(sha1_test Sha1Test.cc)
add_executable(view_data_test HttpViewDataTest.cc) add_executable(view_data_test HttpViewDataTest.cc)
add_executable(orm_result_test OrmResultTest.cc) add_executable(orm_result_test OrmResultTest.cc)
add_executable(md5_test Md5Test.cc ../src/ssl_funcs/Md5.cc)

6
lib/tests/Md5Test.cc Normal file
View File

@ -0,0 +1,6 @@
#include "../lib/src/ssl_funcs/Md5.h"
#include <iostream>
int main()
{
std::cout << Md5Encode::encode("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890") << std::endl;
}

View File

@ -233,7 +233,7 @@ void DbClientImpl::handleNewTask(const DbConnectionPtr &connPtr)
//Then check if there are some sql queries in the buffer //Then check if there are some sql queries in the buffer
{ {
std::lock_guard<std::mutex> guard(_bufferMutex); std::lock_guard<std::mutex> guard(_bufferMutex);
if (_sqlCmdBuffer.size() > 0) if (!_sqlCmdBuffer.empty())
{ {
_busyConnections.insert(connPtr); //For new connections, this sentence is necessary _busyConnections.insert(connPtr); //For new connections, this sentence is necessary
auto cmd = _sqlCmdBuffer.front(); auto cmd = _sqlCmdBuffer.front();

View File

@ -78,7 +78,7 @@ private:
QueryCallback _cb; QueryCallback _cb;
ExceptPtrCallback _exceptCb; ExceptPtrCallback _exceptCb;
}; };
std::list<SqlCmd> _sqlCmdBuffer; std::deque<SqlCmd> _sqlCmdBuffer;
std::mutex _bufferMutex; std::mutex _bufferMutex;
void handleNewTask(const DbConnectionPtr &conn); void handleNewTask(const DbConnectionPtr &conn);

View File

@ -192,7 +192,7 @@ void TransactionImpl::execNewTask()
if (!_isCommitedOrRolledback) if (!_isCommitedOrRolledback)
{ {
auto thisPtr = shared_from_this(); auto thisPtr = shared_from_this();
if (_sqlCmdBuffer.size() > 0) if (!_sqlCmdBuffer.empty())
{ {
auto cmd = _sqlCmdBuffer.front(); auto cmd = _sqlCmdBuffer.front();
_sqlCmdBuffer.pop_front(); _sqlCmdBuffer.pop_front();
@ -223,7 +223,7 @@ void TransactionImpl::execNewTask()
else else
{ {
_isWorking = false; _isWorking = false;
if (_sqlCmdBuffer.size() > 0) if (!_sqlCmdBuffer.empty())
{ {
try try
{ {

View File

@ -37,11 +37,11 @@ Result makeResult(const std::shared_ptr<MYSQL_RES> &r = std::shared_ptr<MYSQL_RE
} // namespace drogon } // namespace drogon
MysqlConnection::MysqlConnection(trantor::EventLoop *loop, const std::string &connInfo) MysqlConnection::MysqlConnection(trantor::EventLoop *loop, const std::string &connInfo)
: DbConnection(loop) : DbConnection(loop),
{ _mysqlPtr(std::shared_ptr<MYSQL>(new MYSQL, [](MYSQL *p) {
_mysqlPtr = std::shared_ptr<MYSQL>(new MYSQL, [](MYSQL *p) {
mysql_close(p); mysql_close(p);
}); }))
{
mysql_init(_mysqlPtr.get()); mysql_init(_mysqlPtr.get());
mysql_options(_mysqlPtr.get(), MYSQL_OPT_NONBLOCK, 0); mysql_options(_mysqlPtr.get(), MYSQL_OPT_NONBLOCK, 0);

@ -1 +1 @@
Subproject commit 4f3bf10eb996b3c44ee2d8f61a3add64d1fb6b1c Subproject commit eb18788056164447715b6c2507a297b54ed519ba