Removing wstringstream usage since it adds unnecessary overhead (#908)

This commit is contained in:
Scott Freeman 2020-01-08 17:35:05 -05:00 committed by Matt Cooley
parent f9c049a84b
commit 8141941208
2 changed files with 20 additions and 25 deletions

View File

@ -263,8 +263,7 @@ namespace GraphControl
if (!validEqs.empty()) if (!validEqs.empty())
{ {
wstringstream ss{}; request = s_getGraphOpeningTags;
ss << s_getGraphOpeningTags;
int numValidEquations = 0; int numValidEquations = 0;
for (Equation ^ eq : validEqs) for (Equation ^ eq : validEqs)
@ -276,15 +275,13 @@ namespace GraphControl
if (numValidEquations++ > 0) if (numValidEquations++ > 0)
{ {
ss << L"<mo>,</mo>"; request += L"<mo>,</mo>";
} }
ss << eq->GetRequest()->Data(); request += eq->GetRequest()->Data();
} }
ss << s_getGraphClosingTags; request += s_getGraphClosingTags;
request = ss.str();
} }
if (graphExpression = m_solver->ParseInput(request)) if (graphExpression = m_solver->ParseInput(request))
@ -374,14 +371,11 @@ namespace GraphControl
{ {
shared_ptr<Graphing::IGraph> graph = m_solver->CreateGrapher(); shared_ptr<Graphing::IGraph> graph = m_solver->CreateGrapher();
wstringstream ss{}; wstring request = s_getGraphOpeningTags;
ss << s_getGraphOpeningTags; request += equation->GetRequest()->Data();
ss << equation->GetRequest()->Data(); request += s_getGraphClosingTags;
ss << s_getGraphClosingTags;
wstring request = ss.str(); if (unique_ptr<IExpression> graphExpression = m_solver->ParseInput(request))
unique_ptr<IExpression> graphExpression;
if (graphExpression = m_solver->ParseInput(request))
{ {
if (graph->TryInitialize(graphExpression.get())) if (graph->TryInitialize(graphExpression.get()))
{ {

View File

@ -24,26 +24,27 @@ namespace GraphControl
String ^ Equation::GetRequest() String ^ Equation::GetRequest()
{ {
wstringstream ss; wstring request;
wstring expr{ Expression->Data() }; wstring_view expr{ Expression->Data() };
// Check for unicode characters of less than, less than or equal to, greater than and greater than or equal to. // Check for unicode characters of less than, less than or equal to, greater than and greater than or equal to.
if (expr.find(L">&#x3E;<") != wstring::npos || expr.find(L">&#x3C;<") != wstring::npos || expr.find(L">&#x2265;<") != wstring::npos if (expr.find(L">&#x3E;<") != wstring_view::npos || expr.find(L">&#x3C;<") != wstring_view::npos || expr.find(L">&#x2265;<") != wstring_view::npos
|| expr.find(L">&#x2264;<") != wstring::npos) || expr.find(L">&#x2264;<") != wstring_view::npos)
{ {
ss << L"<mrow><mi>plotIneq2D</mi><mfenced separators=\"\">"s; request = L"<mrow><mi>plotIneq2D</mi><mfenced separators=\"\">";
} }
else if (expr.find(L">=<") != wstring::npos) else if (expr.find(L">=<") != wstring_view::npos)
{ {
ss << L"<mrow><mi>plotEq2d</mi><mfenced separators=\"\">"; request = L"<mrow><mi>plotEq2d</mi><mfenced separators=\"\">";
} }
else else
{ {
ss << L"<mrow><mi>plot2d</mi><mfenced separators=\"\">"; request = L"<mrow><mi>plot2d</mi><mfenced separators=\"\">";
} }
ss << GetExpression() << L"</mfenced></mrow>"; request += GetExpression();
request += L"</mfenced></mrow>";
return ref new String(ss.str().c_str()); return ref new String(request.c_str());
} }
wstring Equation::GetExpression() wstring Equation::GetExpression()
@ -51,7 +52,7 @@ namespace GraphControl
wstring mathML = Expression->Data(); wstring mathML = Expression->Data();
size_t mathPrefix = 0; size_t mathPrefix = 0;
while ((mathPrefix = mathML.find(s_mathPrefix, mathPrefix)) != std::string::npos) while ((mathPrefix = mathML.find(s_mathPrefix, mathPrefix)) != wstring::npos)
{ {
mathML.replace(mathPrefix, s_mathPrefix.length(), L""); mathML.replace(mathPrefix, s_mathPrefix.length(), L"");
mathPrefix += s_mathPrefix.length(); mathPrefix += s_mathPrefix.length();