mirror of
https://github.com/Microsoft/calculator.git
synced 2025-07-16 02:02:51 -07:00
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:
parent
c7b0baaeda
commit
54d81721cf
8 changed files with 37 additions and 48 deletions
|
@ -22,18 +22,18 @@ UnitConverterDataLoader::UnitConverterDataLoader(GeographicRegion ^ region)
|
|||
: m_currentRegionCode(region->CodeTwoLetter)
|
||||
{
|
||||
m_categoryList = make_shared<vector<UCM::Category>>();
|
||||
m_categoryToUnits = make_shared<UCM::CategoryToUnitVectorMap>();
|
||||
m_categoryIDToUnitsMap = make_shared<UCM::CategoryToUnitVectorMap>();
|
||||
m_ratioMap = make_shared<UCM::UnitToUnitToConversionDataMap>();
|
||||
}
|
||||
|
||||
vector<UCM::Category> UnitConverterDataLoader::LoadOrderedCategories()
|
||||
vector<UCM::Category> UnitConverterDataLoader::GetOrderedCategories()
|
||||
{
|
||||
return *m_categoryList;
|
||||
}
|
||||
|
||||
vector<UCM::Unit> UnitConverterDataLoader::LoadOrderedUnits(const UCM::Category& category)
|
||||
vector<UCM::Unit> UnitConverterDataLoader::GetOrderedUnits(const UCM::Category& category)
|
||||
{
|
||||
return m_categoryToUnits->at(category);
|
||||
return this->m_categoryIDToUnitsMap->at(category.id);
|
||||
}
|
||||
|
||||
unordered_map<UCM::Unit, UCM::ConversionData, UCM::UnitHash> UnitConverterDataLoader::LoadOrderedRatios(const UCM::Unit& unit)
|
||||
|
@ -75,8 +75,8 @@ void UnitConverterDataLoader::LoadData()
|
|||
GetConversionData(categoryToUnitConversionDataMap);
|
||||
GetExplicitConversionData(explicitConversionData); // This is needed for temperature conversions
|
||||
|
||||
m_categoryToUnits->clear();
|
||||
m_ratioMap->clear();
|
||||
this->m_categoryIDToUnitsMap->clear();
|
||||
this->m_ratioMap->clear();
|
||||
for (UCM::Category objectCategory : *m_categoryList)
|
||||
{
|
||||
ViewMode categoryViewMode = NavCategory::Deserialize(objectCategory.id);
|
||||
|
@ -86,7 +86,7 @@ void UnitConverterDataLoader::LoadData()
|
|||
// Currency is an ordered category but we do not want to process it here
|
||||
// because this function is not thread-safe and currency data is asynchronously
|
||||
// loaded.
|
||||
m_categoryToUnits->insert(pair<UCM::Category, std::vector<UCM::Unit>>(objectCategory, {}));
|
||||
this->m_categoryIDToUnitsMap->insert(pair<int, std::vector<UCM::Unit>>(objectCategory.id, {}));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ void UnitConverterDataLoader::LoadData()
|
|||
}
|
||||
|
||||
// Save units per category
|
||||
m_categoryToUnits->insert(pair<UCM::Category, std::vector<UCM::Unit>>(objectCategory, unitList));
|
||||
this->m_categoryIDToUnitsMap->insert(pair<int, std::vector<UCM::Unit>>(objectCategory.id, unitList));
|
||||
|
||||
// For each unit, populate the conversion data
|
||||
for (UCM::Unit unit : unitList)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue