Small code optimization.

This commit is contained in:
spx 2010-11-16 20:12:27 +00:00
parent fc046ac4eb
commit f689bbe6f1
4 changed files with 27 additions and 36 deletions

View File

@ -714,12 +714,9 @@ CMeasure* CConfigParser::GetMeasure(const std::wstring& name)
double CConfigParser::ReadFloat(LPCTSTR section, LPCTSTR key, double defValue) double CConfigParser::ReadFloat(LPCTSTR section, LPCTSTR key, double defValue)
{ {
TCHAR buffer[256]; const std::wstring& result = ReadString(section, key, L"");
swprintf(buffer, L"%f", defValue);
const std::wstring& result = ReadString(section, key, buffer); return (m_LastDefaultUsed) ? defValue : ParseDouble(result, defValue);
return ParseDouble(result, defValue);
} }
std::vector<Gdiplus::REAL> CConfigParser::ReadFloats(LPCTSTR section, LPCTSTR key) std::vector<Gdiplus::REAL> CConfigParser::ReadFloats(LPCTSTR section, LPCTSTR key)
@ -742,21 +739,15 @@ std::vector<Gdiplus::REAL> CConfigParser::ReadFloats(LPCTSTR section, LPCTSTR ke
int CConfigParser::ReadInt(LPCTSTR section, LPCTSTR key, int defValue) int CConfigParser::ReadInt(LPCTSTR section, LPCTSTR key, int defValue)
{ {
TCHAR buffer[32]; const std::wstring& result = ReadString(section, key, L"");
swprintf(buffer, L"%i", defValue);
const std::wstring& result = ReadString(section, key, buffer); return (m_LastDefaultUsed) ? defValue : (int)ParseDouble(result, defValue, true);
return (int)ParseDouble(result, defValue, true);
} }
// Works as ReadFloat except if the value is surrounded by parenthesis in which case it tries to evaluate the formula // Works as ReadFloat except if the value is surrounded by parenthesis in which case it tries to evaluate the formula
double CConfigParser::ReadFormula(LPCTSTR section, LPCTSTR key, double defValue) double CConfigParser::ReadFormula(LPCTSTR section, LPCTSTR key, double defValue)
{ {
TCHAR buffer[256]; const std::wstring& result = ReadString(section, key, L"");
swprintf(buffer, L"%f", defValue);
const std::wstring& result = ReadString(section, key, buffer);
// Formulas must be surrounded by parenthesis // Formulas must be surrounded by parenthesis
if (!result.empty() && result[0] == L'(' && result[result.size() - 1] == L')') if (!result.empty() && result[0] == L'(' && result[result.size() - 1] == L')')
@ -771,7 +762,7 @@ double CConfigParser::ReadFormula(LPCTSTR section, LPCTSTR key, double defValue)
return resultValue; return resultValue;
} }
return ParseDouble(result, defValue); return (m_LastDefaultUsed) ? defValue : ParseDouble(result, defValue);
} }
// Returns an int if the formula was read successfully, -1 for failure. // Returns an int if the formula was read successfully, -1 for failure.
@ -797,12 +788,9 @@ int CConfigParser::ReadFormula(const std::wstring& result, double* resultValue)
Color CConfigParser::ReadColor(LPCTSTR section, LPCTSTR key, const Color& defValue) Color CConfigParser::ReadColor(LPCTSTR section, LPCTSTR key, const Color& defValue)
{ {
TCHAR buffer[128]; const std::wstring& result = ReadString(section, key, L"");
swprintf(buffer, L"%i, %i, %i, %i", defValue.GetR(), defValue.GetG(), defValue.GetB(), defValue.GetA());
const std::wstring& result = ReadString(section, key, buffer); return (m_LastDefaultUsed) ? defValue : ParseColor(result.c_str());
return ParseColor(result.c_str());
} }
/* /*

View File

@ -259,7 +259,7 @@ void CMeterHistogram::ReadConfig(const WCHAR* section)
m_BothColor = parser.ReadColor(section, L"BothColor", Color::Yellow); m_BothColor = parser.ReadColor(section, L"BothColor", Color::Yellow);
m_SecondaryMeasureName = parser.ReadString(section, L"MeasureName2", L""); m_SecondaryMeasureName = parser.ReadString(section, L"MeasureName2", L"");
if (m_SecondaryMeasureName == L"") if (m_SecondaryMeasureName.empty())
{ {
m_SecondaryMeasureName = parser.ReadString(section, L"SecondaryMeasureName", L""); m_SecondaryMeasureName = parser.ReadString(section, L"SecondaryMeasureName", L"");
} }

View File

@ -447,7 +447,7 @@ void CMeterImage::ReadConfig(const WCHAR* section)
if (alpha != tint.GetAlpha()) if (alpha != tint.GetAlpha())
{ {
tint = Color(alpha, tint.GetRed(), tint.GetGreen(), tint.GetBlue()); tint.SetValue(Color::MakeARGB(alpha, tint.GetRed(), tint.GetGreen(), tint.GetBlue()));
} }
m_ColorMatrix = c_IdentifyMatrix; m_ColorMatrix = c_IdentifyMatrix;

View File

@ -259,22 +259,25 @@ void CMeterString::ReadConfig(const WCHAR* section)
m_MeasureNames.clear(); m_MeasureNames.clear();
// Check for extra measures // Check for extra measures
int i = 2; if (!m_MeasureName.empty())
bool loop = true;
do
{ {
swprintf(tmpName, L"MeasureName%i", i); int i = 2;
std::wstring measure = parser.ReadString(section, tmpName, L""); bool loop = true;
if (!measure.empty()) do
{ {
m_MeasureNames.push_back(measure); swprintf(tmpName, L"MeasureName%i", i);
} std::wstring measure = parser.ReadString(section, tmpName, L"");
else if (!measure.empty())
{ {
loop = false; m_MeasureNames.push_back(measure);
} }
++i; else
} while(loop); {
loop = false;
}
++i;
} while(loop);
}
m_Color = parser.ReadColor(section, L"FontColor", Color::Black); m_Color = parser.ReadColor(section, L"FontColor", Color::Black);
m_EffectColor = parser.ReadColor(section, L"FontEffectColor", Color::Black); m_EffectColor = parser.ReadColor(section, L"FontEffectColor", Color::Black);