Pre-Unit conversion work refactor, replace category with categoryID (#1260)
Removed category as key in category to unit vector map and replaced with category id to reduce memory footprint.
This commit is contained in:
committed by
GitHub
parent
c7b0baaeda
commit
54d81721cf
@@ -109,7 +109,7 @@ CategorySelectionInitializer UnitConverter::SetCurrentCategory(const Category& i
|
||||
{
|
||||
if (m_currentCategory.id != input.id)
|
||||
{
|
||||
for (auto& unit : m_categoryToUnits[m_currentCategory])
|
||||
for (auto& unit : m_categoryToUnits[m_currentCategory.id])
|
||||
{
|
||||
unit.isConversionSource = (unit.id == m_fromType.id);
|
||||
unit.isConversionTarget = (unit.id == m_toType.id);
|
||||
@@ -121,7 +121,7 @@ CategorySelectionInitializer UnitConverter::SetCurrentCategory(const Category& i
|
||||
}
|
||||
}
|
||||
|
||||
newUnitList = m_categoryToUnits[input];
|
||||
newUnitList = m_categoryToUnits[input.id];
|
||||
}
|
||||
|
||||
InitializeSelectedUnits();
|
||||
@@ -283,7 +283,7 @@ void UnitConverter::RestoreUserPreferences(wstring_view userPreferences)
|
||||
m_currentCategory = StringToCategory(outerTokens[2]);
|
||||
|
||||
// Only restore from the saved units if they are valid in the current available units.
|
||||
auto itr = m_categoryToUnits.find(m_currentCategory);
|
||||
auto itr = m_categoryToUnits.find(m_currentCategory.id);
|
||||
if (itr != m_categoryToUnits.end())
|
||||
{
|
||||
const auto& curUnits = itr->second;
|
||||
@@ -713,10 +713,8 @@ vector<tuple<wstring, Unit>> UnitConverter::CalculateSuggested()
|
||||
/// </summary>
|
||||
void UnitConverter::ResetCategoriesAndRatios()
|
||||
{
|
||||
m_categories = m_dataLoader->LoadOrderedCategories();
|
||||
|
||||
m_switchedActive = false;
|
||||
|
||||
m_categories = m_dataLoader->GetOrderedCategories();
|
||||
if (m_categories.empty())
|
||||
{
|
||||
return;
|
||||
@@ -738,8 +736,8 @@ void UnitConverter::ResetCategoriesAndRatios()
|
||||
continue;
|
||||
}
|
||||
|
||||
vector<Unit> units = activeDataLoader->LoadOrderedUnits(category);
|
||||
m_categoryToUnits[category] = units;
|
||||
vector<Unit> units = activeDataLoader->GetOrderedUnits(category);
|
||||
m_categoryToUnits[category.id] = units;
|
||||
|
||||
// Just because the units are empty, doesn't mean the user can't select this category,
|
||||
// we just want to make sure we don't let an unready category be the default.
|
||||
@@ -789,7 +787,7 @@ void UnitConverter::InitializeSelectedUnits()
|
||||
return;
|
||||
}
|
||||
|
||||
auto itr = m_categoryToUnits.find(m_currentCategory);
|
||||
auto itr = m_categoryToUnits.find(m_currentCategory.id);
|
||||
if (itr == m_categoryToUnits.end())
|
||||
{
|
||||
return;
|
||||
|
@@ -116,15 +116,6 @@ namespace UnitConversionManager
|
||||
}
|
||||
};
|
||||
|
||||
class CategoryHash
|
||||
{
|
||||
public:
|
||||
size_t operator()(const Category& x) const
|
||||
{
|
||||
return x.id;
|
||||
}
|
||||
};
|
||||
|
||||
struct SuggestedValueIntermediate
|
||||
{
|
||||
double magnitude;
|
||||
@@ -171,7 +162,7 @@ namespace UnitConversionManager
|
||||
std::unordered_map<UnitConversionManager::Unit, UnitConversionManager::ConversionData, UnitConversionManager::UnitHash>,
|
||||
UnitConversionManager::UnitHash>
|
||||
UnitToUnitToConversionDataMap;
|
||||
typedef std::unordered_map<UnitConversionManager::Category, std::vector<UnitConversionManager::Unit>, UnitConversionManager::CategoryHash>
|
||||
typedef std::unordered_map<int, std::vector<UnitConversionManager::Unit>>
|
||||
CategoryToUnitVectorMap;
|
||||
|
||||
class IViewModelCurrencyCallback
|
||||
@@ -190,8 +181,8 @@ namespace UnitConversionManager
|
||||
public:
|
||||
virtual ~IConverterDataLoader(){};
|
||||
virtual void LoadData() = 0; // prepare data if necessary before calling other functions
|
||||
virtual std::vector<Category> LoadOrderedCategories() = 0;
|
||||
virtual std::vector<Unit> LoadOrderedUnits(const Category& c) = 0;
|
||||
virtual std::vector<Category> GetOrderedCategories() = 0;
|
||||
virtual std::vector<Unit> GetOrderedUnits(const Category& c) = 0;
|
||||
virtual std::unordered_map<Unit, ConversionData, UnitHash> LoadOrderedRatios(const Unit& u) = 0;
|
||||
virtual bool SupportsCategory(const Category& target) = 0;
|
||||
};
|
||||
|
Reference in New Issue
Block a user