mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-25 10:09:36 +02:00
PageCompiler: optimize handler code by removing useless statements
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// CodeWriter.cpp
|
||||
//
|
||||
// $Id: //poco/1.4/PageCompiler/src/CodeWriter.cpp#3 $
|
||||
// $Id: //poco/1.7/PageCompiler/src/CodeWriter.cpp#4 $
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
@@ -351,7 +351,7 @@ void CodeWriter::writeContent(std::ostream& ostr)
|
||||
if (buffered)
|
||||
{
|
||||
ostr << "\tstd::stringstream responseStream;\n";
|
||||
ostr << _page.handler().str();
|
||||
ostr << cleanupHandler(_page.handler().str());
|
||||
if (!chunked)
|
||||
{
|
||||
ostr << "\tresponse.setContentLength(static_cast<int>(responseStream.tellp()));\n";
|
||||
@@ -363,13 +363,31 @@ void CodeWriter::writeContent(std::ostream& ostr)
|
||||
ostr << "\tstd::ostream& _responseStream = response.send();\n"
|
||||
<< "\tPoco::DeflatingOutputStream _gzipStream(_responseStream, Poco::DeflatingStreamBuf::STREAM_GZIP, " << compressionLevel << ");\n"
|
||||
<< "\tstd::ostream& responseStream = _compressResponse ? _gzipStream : _responseStream;\n";
|
||||
ostr << _page.handler().str();
|
||||
ostr << cleanupHandler(_page.handler().str());
|
||||
ostr << "\tif (_compressResponse) _gzipStream.close();\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
ostr << "\tstd::ostream& responseStream = response.send();\n";
|
||||
ostr << _page.handler().str();
|
||||
ostr << cleanupHandler(_page.handler().str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string CodeWriter::cleanupHandler(std::string handler)
|
||||
{
|
||||
static const std::string EMPTY_WRITE("\tresponseStream << \"\";\n");
|
||||
static const std::string NEWLINE_WRITE("\tresponseStream << \"\\n\";\n");
|
||||
static const std::string DOUBLE_NEWLINE_WRITE("\tresponseStream << \"\\n\";\n\tresponseStream << \"\\n\";\n");
|
||||
static const std::string EMPTY;
|
||||
|
||||
// remove empty writes
|
||||
Poco::replaceInPlace(handler, EMPTY_WRITE, EMPTY);
|
||||
// remove consecutive newlines
|
||||
while (handler.find(DOUBLE_NEWLINE_WRITE) != std::string::npos)
|
||||
{
|
||||
Poco::replaceInPlace(handler, DOUBLE_NEWLINE_WRITE, NEWLINE_WRITE);
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user