Modify something to improve performance
This commit is contained in:
parent
e69697466d
commit
fb5bbde277
|
@ -118,7 +118,7 @@ class HttpResponse
|
|||
|
||||
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;
|
||||
|
||||
|
|
|
@ -221,7 +221,6 @@ const std::string HttpFile::getMd5() const
|
|||
MD5_Final(md5, &c);
|
||||
return binaryStringToHex(md5, 16);
|
||||
#else
|
||||
Md5Encode encode;
|
||||
return encode.Encode(_fileContent);
|
||||
return Md5Encode::encode(_fileContent);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ class HttpResponseImpl : public HttpResponse
|
|||
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;
|
||||
setContentType(web_content_type_and_charset_to_string(type, charSet));
|
||||
|
|
|
@ -208,7 +208,7 @@ void HttpServerContext::pushRquestToPipeLine(const HttpRequestPtr &req)
|
|||
}
|
||||
HttpRequestPtr HttpServerContext::getFirstRequest() const
|
||||
{
|
||||
if (_requestPipeLine.size() > 0)
|
||||
if (!_requestPipeLine.empty())
|
||||
{
|
||||
return _requestPipeLine.front().first;
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ HttpRequestPtr HttpServerContext::getFirstRequest() const
|
|||
}
|
||||
HttpResponsePtr HttpServerContext::getFirstResponse() const
|
||||
{
|
||||
if (_requestPipeLine.size() > 0)
|
||||
if (!_requestPipeLine.empty())
|
||||
{
|
||||
return _requestPipeLine.front().second;
|
||||
}
|
||||
|
|
|
@ -231,7 +231,7 @@ std::string Md5Encode::GetHexStr(unsigned int num_str)
|
|||
// function: Encode
|
||||
// @param src_info:要加密的信息
|
||||
// return :加密后的MD5值
|
||||
std::string Md5Encode::Encode(std::string src_info)
|
||||
std::string Md5Encode::encode(const std::string &src_info)
|
||||
{
|
||||
ParamDynamic param;
|
||||
param.ua_ = kA;
|
||||
|
@ -244,9 +244,8 @@ std::string Md5Encode::Encode(std::string src_info)
|
|||
param.vd_last_ = kD;
|
||||
|
||||
std::string result;
|
||||
const char *src_data = src_info.c_str();
|
||||
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;
|
||||
for (int i = 0; i < total_byte / (BIT_OF_GROUP / BIT_OF_BYTE); ++i)
|
||||
{
|
||||
|
|
|
@ -60,20 +60,18 @@ class Md5Encode
|
|||
};
|
||||
|
||||
public:
|
||||
Md5Encode()
|
||||
{
|
||||
}
|
||||
std::string Encode(std::string src_info);
|
||||
|
||||
static std::string encode(const std::string &src_info);
|
||||
|
||||
protected:
|
||||
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);
|
||||
void RoundF(char *data_512_ptr, ParamDynamic ¶m);
|
||||
void RoundG(char *data_512_ptr, ParamDynamic ¶m);
|
||||
void RoundH(char *data_512_ptr, ParamDynamic ¶m);
|
||||
void RoundI(char *data_512_ptr, ParamDynamic ¶m);
|
||||
void RotationCalculate(char *data_512_ptr, ParamDynamic ¶m);
|
||||
std::string GetHexStr(unsigned int num_str);
|
||||
static UInt32 CycleMoveLeft(UInt32 src_num, int bit_num_to_move);
|
||||
static void RoundF(char *data_512_ptr, ParamDynamic ¶m);
|
||||
static void RoundG(char *data_512_ptr, ParamDynamic ¶m);
|
||||
static void RoundH(char *data_512_ptr, ParamDynamic ¶m);
|
||||
static void RoundI(char *data_512_ptr, ParamDynamic ¶m);
|
||||
static void RotationCalculate(char *data_512_ptr, ParamDynamic ¶m);
|
||||
static std::string GetHexStr(unsigned int num_str);
|
||||
static UInt32 FillData(const char *in_data_ptr, int data_byte_len, char **out_data_ptr);
|
||||
|
||||
private:
|
||||
// 幻数定义
|
||||
|
|
|
@ -7,4 +7,4 @@ add_executable(class_name_test ClassNameTest.cc)
|
|||
add_executable(sha1_test Sha1Test.cc)
|
||||
add_executable(view_data_test HttpViewDataTest.cc)
|
||||
add_executable(orm_result_test OrmResultTest.cc)
|
||||
|
||||
add_executable(md5_test Md5Test.cc ../src/ssl_funcs/Md5.cc)
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#include "../lib/src/ssl_funcs/Md5.h"
|
||||
#include <iostream>
|
||||
int main()
|
||||
{
|
||||
std::cout << Md5Encode::encode("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890") << std::endl;
|
||||
}
|
|
@ -233,7 +233,7 @@ void DbClientImpl::handleNewTask(const DbConnectionPtr &connPtr)
|
|||
//Then check if there are some sql queries in the buffer
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(_bufferMutex);
|
||||
if (_sqlCmdBuffer.size() > 0)
|
||||
if (!_sqlCmdBuffer.empty())
|
||||
{
|
||||
_busyConnections.insert(connPtr); //For new connections, this sentence is necessary
|
||||
auto cmd = _sqlCmdBuffer.front();
|
||||
|
|
|
@ -78,7 +78,7 @@ private:
|
|||
QueryCallback _cb;
|
||||
ExceptPtrCallback _exceptCb;
|
||||
};
|
||||
std::list<SqlCmd> _sqlCmdBuffer;
|
||||
std::deque<SqlCmd> _sqlCmdBuffer;
|
||||
std::mutex _bufferMutex;
|
||||
|
||||
void handleNewTask(const DbConnectionPtr &conn);
|
||||
|
|
|
@ -192,7 +192,7 @@ void TransactionImpl::execNewTask()
|
|||
if (!_isCommitedOrRolledback)
|
||||
{
|
||||
auto thisPtr = shared_from_this();
|
||||
if (_sqlCmdBuffer.size() > 0)
|
||||
if (!_sqlCmdBuffer.empty())
|
||||
{
|
||||
auto cmd = _sqlCmdBuffer.front();
|
||||
_sqlCmdBuffer.pop_front();
|
||||
|
@ -223,7 +223,7 @@ void TransactionImpl::execNewTask()
|
|||
else
|
||||
{
|
||||
_isWorking = false;
|
||||
if (_sqlCmdBuffer.size() > 0)
|
||||
if (!_sqlCmdBuffer.empty())
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -37,11 +37,11 @@ Result makeResult(const std::shared_ptr<MYSQL_RES> &r = std::shared_ptr<MYSQL_RE
|
|||
} // namespace drogon
|
||||
|
||||
MysqlConnection::MysqlConnection(trantor::EventLoop *loop, const std::string &connInfo)
|
||||
: DbConnection(loop)
|
||||
: DbConnection(loop),
|
||||
_mysqlPtr(std::shared_ptr<MYSQL>(new MYSQL, [](MYSQL *p) {
|
||||
mysql_close(p);
|
||||
}))
|
||||
{
|
||||
_mysqlPtr = std::shared_ptr<MYSQL>(new MYSQL, [](MYSQL *p) {
|
||||
mysql_close(p);
|
||||
});
|
||||
mysql_init(_mysqlPtr.get());
|
||||
mysql_options(_mysqlPtr.get(), MYSQL_OPT_NONBLOCK, 0);
|
||||
|
||||
|
|
2
trantor
2
trantor
|
@ -1 +1 @@
|
|||
Subproject commit 4f3bf10eb996b3c44ee2d8f61a3add64d1fb6b1c
|
||||
Subproject commit eb18788056164447715b6c2507a297b54ed519ba
|
Loading…
Reference in New Issue