From 0e1486f0bed3a3f8d867f9220d3898063bcfe459 Mon Sep 17 00:00:00 2001 From: spx Date: Thu, 25 Nov 2010 15:34:49 +0000 Subject: [PATCH] Code optimization. --- Library/AboutDialog.cpp | 4 ++-- Library/Litestep.cpp | 2 +- Library/Measure.cpp | 5 ++++- Library/MeasurePlugin.cpp | 11 +++++++++-- Library/MeasureRegistry.cpp | 7 ++++++- Library/Meter.cpp | 24 +++++++++++++---------- Library/MeterBar.cpp | 7 ++++++- Library/MeterBitmap.cpp | 7 ++++++- Library/MeterHistogram.cpp | 7 ++++++- Library/MeterImage.cpp | 7 ++++++- Library/MeterLine.cpp | 7 ++++++- Library/MeterString.cpp | 39 +++++++++++++++++++++++++++++++------ Library/MeterWindow.cpp | 14 ++++++------- 13 files changed, 106 insertions(+), 35 deletions(-) diff --git a/Library/AboutDialog.cpp b/Library/AboutDialog.cpp index 988b5a7e..562553c1 100644 --- a/Library/AboutDialog.cpp +++ b/Library/AboutDialog.cpp @@ -210,7 +210,7 @@ void UpdateAboutStatistics(LPCTSTR entryName) CMeasure::GetScaledValue(1, maxVal, buffer); range += buffer; - if (name && wcslen(name) > 0) + if (name && *name) { if (index < count) { @@ -365,7 +365,7 @@ void ScanPlugins() if (GetAuthorFunc) { LPCTSTR author = GetAuthorFunc(); - if (author && wcslen(author) > 0) + if (author && *author) { info.author = author; } diff --git a/Library/Litestep.cpp b/Library/Litestep.cpp index da081b13..46f820ec 100644 --- a/Library/Litestep.cpp +++ b/Library/Litestep.cpp @@ -332,7 +332,7 @@ HINSTANCE LSExecute(HWND Owner, LPCTSTR szCommand, int nShowCmd) HINSTANCE ExecuteCommand(HWND Owner, LPCTSTR szCommand, int nShowCmd, LPCTSTR szVerb) { // The stub implementation (some of this code is taken from lsapi.cpp) - if (szCommand == NULL || wcslen(szCommand) == 0) return NULL; + if (szCommand == NULL || *szCommand == 0) return NULL; std::wstring args; std::wstring command = szCommand; diff --git a/Library/Measure.cpp b/Library/Measure.cpp index 5f3175c9..93b5dbce 100644 --- a/Library/Measure.cpp +++ b/Library/Measure.cpp @@ -670,7 +670,10 @@ CMeasure* CMeasure::Create(const WCHAR* measure, CMeterWindow* meterWindow) } // Error - throw CError(std::wstring(L"Measure=") + measure + L" is not valid.", __LINE__, __FILE__); + std::wstring error = L"Measure="; + error += measure; + error += L" is not valid."; + throw CError(error, __LINE__, __FILE__); return NULL; } diff --git a/Library/MeasurePlugin.cpp b/Library/MeasurePlugin.cpp index e6fc3709..5534931f 100644 --- a/Library/MeasurePlugin.cpp +++ b/Library/MeasurePlugin.cpp @@ -151,7 +151,10 @@ void CMeasurePlugin::ReadConfig(CConfigParser& parser, const WCHAR* section) if (m_Plugin == NULL) { - throw CError(std::wstring(L"Rainmeter plugin ") + m_PluginName + L" not found!", __LINE__, __FILE__); + std::wstring error = L"Rainmeter plugin "; + error += m_PluginName; + error += L" not found!"; + throw CError(error, __LINE__, __FILE__); } } @@ -165,7 +168,11 @@ void CMeasurePlugin::ReadConfig(CConfigParser& parser, const WCHAR* section) if (UpdateFunc == NULL && UpdateFunc2 == NULL && GetStringFunc == NULL) { FreeLibrary(m_Plugin); - throw CError(std::wstring(L"Rainmeter plugin ") + m_PluginName + L" doesn't export Update or GetString function!", __LINE__, __FILE__); + + std::wstring error = L"Rainmeter plugin "; + error += m_PluginName; + error += L" doesn't export Update or GetString function!"; + throw CError(error, __LINE__, __FILE__); } // Initialize the plugin diff --git a/Library/MeasureRegistry.cpp b/Library/MeasureRegistry.cpp index d99c9c18..c99af4ae 100644 --- a/Library/MeasureRegistry.cpp +++ b/Library/MeasureRegistry.cpp @@ -149,7 +149,12 @@ void CMeasureRegistry::ReadConfig(CConfigParser& parser, const WCHAR* section) } else { - throw CError(std::wstring(L"HKEY=") + keyname + L" is not valid in measure [" + section + L"].", __LINE__, __FILE__); + std::wstring error = L"HKEY="; + error += keyname; + error += L" is not valid in measure ["; + error += m_Name; + error += L"]."; + throw CError(error, __LINE__, __FILE__); } m_RegKeyName = parser.ReadString(section, L"RegKey", L""); diff --git a/Library/Meter.cpp b/Library/Meter.cpp index 31f52964..f98412f2 100644 --- a/Library/Meter.cpp +++ b/Library/Meter.cpp @@ -430,13 +430,6 @@ void CMeter::ReadConfig(const WCHAR* section) std::wstring group = parser.ReadString(section, L"Group", L""); InitializeGroup(group); - -/* Are these necessary? - if (m_W == 0 || m_H == 0) - { - throw CError(std::wstring(L"The meter ") + section + L" has zero dimensions.", __LINE__, __FILE__); - } -*/ } /* @@ -451,7 +444,10 @@ void CMeter::BindMeasure(const std::list& measures) // The meter is not bound to anything if (m_MeasureName.empty()) { - throw CError(std::wstring(L"The meter [") + m_Name + L"] is not bound to anything!", __LINE__, __FILE__); + std::wstring error = L"The meter ["; + error += m_Name; + error += L"] is not bound to anything!"; + throw CError(error, __LINE__, __FILE__); } // Go through the list and check it there is a measure for us @@ -466,7 +462,12 @@ void CMeter::BindMeasure(const std::list& measures) } // Error :) - throw CError(std::wstring(L"The meter [") + m_Name + L"] cannot be bound with [" + m_MeasureName + L"]!", __LINE__, __FILE__); + std::wstring error = L"The meter ["; + error += m_Name; + error += L"] cannot be bound with ["; + error += m_MeasureName; + error += L"]!"; + throw CError(error, __LINE__, __FILE__); } /* @@ -516,7 +517,10 @@ CMeter* CMeter::Create(const WCHAR* meter, CMeterWindow* meterWindow) } // Error - throw CError(std::wstring(L"Meter=") + meter + L" is not valid.", __LINE__, __FILE__); + std::wstring error = L"Meter="; + error += meter; + error += L" is not valid."; + throw CError(error, __LINE__, __FILE__); return NULL; } diff --git a/Library/MeterBar.cpp b/Library/MeterBar.cpp index 599a5de7..021fef57 100644 --- a/Library/MeterBar.cpp +++ b/Library/MeterBar.cpp @@ -126,7 +126,12 @@ void CMeterBar::ReadConfig(const WCHAR* section) } else { - throw CError(std::wstring(L"BarOrientation=") + orientation + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__); + std::wstring error = L"BarOrientation="; + error += orientation; + error += L" is not valid in meter ["; + error += m_Name; + error += L"]."; + throw CError(error, __LINE__, __FILE__); } if (m_Initialized) diff --git a/Library/MeterBitmap.cpp b/Library/MeterBitmap.cpp index d0dd8eff..f7b57f45 100644 --- a/Library/MeterBitmap.cpp +++ b/Library/MeterBitmap.cpp @@ -211,7 +211,12 @@ void CMeterBitmap::ReadConfig(const WCHAR* section) } else { - throw CError(std::wstring(L"BitmapAlign=") + align + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__); + std::wstring error = L"BitmapAlign="; + error += align; + error += L" is not valid in meter ["; + error += m_Name; + error += L"]."; + throw CError(error, __LINE__, __FILE__); } if (m_Initialized) diff --git a/Library/MeterHistogram.cpp b/Library/MeterHistogram.cpp index fbd87c95..a460b756 100644 --- a/Library/MeterHistogram.cpp +++ b/Library/MeterHistogram.cpp @@ -580,6 +580,11 @@ void CMeterHistogram::BindMeasure(const std::list& measures) } } - throw CError(std::wstring(L"The meter [") + m_Name + L"] cannot be bound with [" + m_SecondaryMeasureName + L"]!", __LINE__, __FILE__); + std::wstring error = L"The meter ["; + error += m_Name; + error += L"] cannot be bound with ["; + error += m_SecondaryMeasureName; + error += L"]!"; + throw CError(error, __LINE__, __FILE__); } } diff --git a/Library/MeterImage.cpp b/Library/MeterImage.cpp index 0fe89bc6..f484c265 100644 --- a/Library/MeterImage.cpp +++ b/Library/MeterImage.cpp @@ -539,7 +539,12 @@ void CMeterImage::ReadConfig(const WCHAR* section) } else { - throw CError(std::wstring(L"ImageFlip=") + flip + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__); + std::wstring error = L"ImageFlip="; + error += flip; + error += L" is not valid in meter ["; + error += m_Name; + error += L"]."; + throw CError(error, __LINE__, __FILE__); } m_Rotate = (REAL)parser.ReadFloat(section, L"ImageRotate", 0.0); diff --git a/Library/MeterLine.cpp b/Library/MeterLine.cpp index 497cfad5..7fc68d72 100644 --- a/Library/MeterLine.cpp +++ b/Library/MeterLine.cpp @@ -397,7 +397,12 @@ void CMeterLine::BindMeasure(const std::list& measures) if (i == measures.end()) { - throw CError(std::wstring(L"The meter [") + m_Name + L"] cannot be bound with [" + (*j) + L"]!", __LINE__, __FILE__); + std::wstring error = L"The meter ["; + error += m_Name; + error += L"] cannot be bound with ["; + error += (*j); + error += L"]!"; + throw CError(error, __LINE__, __FILE__); } } CMeter::SetAllMeasures(m_Measures); diff --git a/Library/MeterString.cpp b/Library/MeterString.cpp index 88641cf9..4d39a87f 100644 --- a/Library/MeterString.cpp +++ b/Library/MeterString.cpp @@ -230,7 +230,9 @@ void CMeterString::Initialize() if (m_FontSize != 0) { - throw CError(std::wstring(L"Unable to create font: ") + m_FontFace, __LINE__, __FILE__); + std::wstring error = L"Unable to create font: "; + error += m_FontFace; + throw CError(error, __LINE__, __FILE__); } } } @@ -331,7 +333,12 @@ void CMeterString::ReadConfig(const WCHAR* section) } else { - throw CError(std::wstring(L"StringAlign=") + align + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__); + std::wstring error = L"StringAlign="; + error += align; + error += L" is not valid in meter ["; + error += m_Name; + error += L"]."; + throw CError(error, __LINE__, __FILE__); } std::wstring stringCase = parser.ReadString(section, L"StringCase", L"NONE"); @@ -354,7 +361,12 @@ void CMeterString::ReadConfig(const WCHAR* section) } else { - throw CError(std::wstring(L"StringCase=") + stringCase + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__); + std::wstring error = L"StringCase="; + error += stringCase; + error += L" is not valid in meter ["; + error += m_Name; + error += L"]."; + throw CError(error, __LINE__, __FILE__); } std::wstring style = parser.ReadString(section, L"StringStyle", L"NORMAL"); @@ -377,7 +389,12 @@ void CMeterString::ReadConfig(const WCHAR* section) } else { - throw CError(std::wstring(L"StringStyle=") + style + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__); + std::wstring error = L"StringStyle="; + error += style; + error += L" is not valid in meter ["; + error += m_Name; + error += L"]."; + throw CError(error, __LINE__, __FILE__); } std::wstring effect = parser.ReadString(section, L"StringEffect", L"NONE"); @@ -396,7 +413,12 @@ void CMeterString::ReadConfig(const WCHAR* section) } else { - throw CError(std::wstring(L"StringEffect=") + effect + L" is not valid in meter [" + m_Name + L"].", __LINE__, __FILE__); + std::wstring error = L"StringEffect="; + error += effect; + error += L" is not valid in meter ["; + error += m_Name; + error += L"]."; + throw CError(error, __LINE__, __FILE__); } if (-1 != (int)parser.ReadFormula(section, L"W", -1) && -1 != (int)parser.ReadFormula(section, L"H", -1)) @@ -634,7 +656,12 @@ void CMeterString::BindMeasure(const std::list& measures) if (i == measures.end()) { - throw CError(std::wstring(L"The meter [") + m_Name + L"] cannot be bound with [" + (*j) + L"]!", __LINE__, __FILE__); + std::wstring error = L"The meter ["; + error += m_Name; + error += L"] cannot be bound with ["; + error += (*j); + error += L"]!"; + throw CError(error, __LINE__, __FILE__); } } CMeter::SetAllMeasures(m_Measures); diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index b16726cd..83a248a6 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -955,7 +955,7 @@ void CMeterWindow::RunBang(BANGCOMMAND bang, const WCHAR* arg) */ void CMeterWindow::ShowMeter(const WCHAR* name, bool group) { - if (name == NULL || wcslen(name) == 0) return; + if (name == NULL || *name == 0) return; std::list::const_iterator j = m_Meters.begin(); for( ; j != m_Meters.end(); ++j) @@ -985,7 +985,7 @@ void CMeterWindow::ShowMeter(const WCHAR* name, bool group) */ void CMeterWindow::HideMeter(const WCHAR* name, bool group) { - if (name == NULL || wcslen(name) == 0) return; + if (name == NULL || *name == 0) return; std::list::const_iterator j = m_Meters.begin(); for( ; j != m_Meters.end(); ++j) @@ -1015,7 +1015,7 @@ void CMeterWindow::HideMeter(const WCHAR* name, bool group) */ void CMeterWindow::ToggleMeter(const WCHAR* name, bool group) { - if (name == NULL || wcslen(name) == 0) return; + if (name == NULL || *name == 0) return; std::list::const_iterator j = m_Meters.begin(); for( ; j != m_Meters.end(); ++j) @@ -1052,7 +1052,7 @@ void CMeterWindow::ToggleMeter(const WCHAR* name, bool group) */ void CMeterWindow::MoveMeter(int x, int y, const WCHAR* name) { - if (name == NULL || wcslen(name) == 0) return; + if (name == NULL || *name == 0) return; std::list::const_iterator j = m_Meters.begin(); for( ; j != m_Meters.end(); ++j) @@ -1077,7 +1077,7 @@ void CMeterWindow::MoveMeter(int x, int y, const WCHAR* name) */ void CMeterWindow::EnableMeasure(const WCHAR* name, bool group) { - if (name == NULL || wcslen(name) == 0) return; + if (name == NULL || *name == 0) return; std::list::const_iterator i = m_Measures.begin(); for( ; i != m_Measures.end(); ++i) @@ -1107,7 +1107,7 @@ void CMeterWindow::EnableMeasure(const WCHAR* name, bool group) */ void CMeterWindow::DisableMeasure(const WCHAR* name, bool group) { - if (name == NULL || wcslen(name) == 0) return; + if (name == NULL || *name == 0) return; std::list::const_iterator i = m_Measures.begin(); for( ; i != m_Measures.end(); ++i) @@ -1137,7 +1137,7 @@ void CMeterWindow::DisableMeasure(const WCHAR* name, bool group) */ void CMeterWindow::ToggleMeasure(const WCHAR* name, bool group) { - if (name == NULL || wcslen(name) == 0) return; + if (name == NULL || *name == 0) return; std::list::const_iterator i = m_Measures.begin(); for( ; i != m_Measures.end(); ++i)