From f1d3a34101014fcf1f1294d588944cc3fe7ccb36 Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Tue, 30 Aug 2016 11:48:46 +0300 Subject: [PATCH] names optimization and fix --- drape_frontend/stylist.cpp | 8 ++-- indexer/feature_utils.cpp | 9 +++-- indexer/indexer_tests/feature_names_test.cpp | 39 ++++++++++++++++++++ indexer/indexer_tests/indexer_tests.pro | 1 + 4 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 indexer/indexer_tests/feature_names_test.cpp diff --git a/drape_frontend/stylist.cpp b/drape_frontend/stylist.cpp index 56e7edec63..54df0b0f8a 100644 --- a/drape_frontend/stylist.cpp +++ b/drape_frontend/stylist.cpp @@ -214,14 +214,14 @@ void CaptionDescription::FormatCaptions(FeatureType const & f, { if (!auxCaptionExists && !m_auxText.empty() && type != feature::GEOM_LINE) { - f.GetReadableName(m_mainText); - if (m_mainText == m_auxText) - m_auxText.clear(); + m_mainText.swap(m_auxText); + m_auxText.clear(); } if (mainTextType == drule::text_type_housenumber) { - m_mainText = move(m_houseNumber); + m_mainText.swap(m_houseNumber); + m_houseNumber.clear(); } else if (mainTextType == drule::text_type_name) { diff --git a/indexer/feature_utils.cpp b/indexer/feature_utils.cpp index 86a5e5203a..696b35d5c0 100644 --- a/indexer/feature_utils.cpp +++ b/indexer/feature_utils.cpp @@ -37,6 +37,12 @@ void GetMwmLangName(FeatureID const & id, StringUtf8Multilang const & src, strin void GetNames(FeatureID const & id, StringUtf8Multilang const & src, string & primary, string & secondary) { + primary.clear(); + secondary.clear(); + + if (src.IsEmpty()) + return; + vector primaryCodes = {StringUtf8Multilang::kDefaultCode}; vector secondaryCodes = {StringUtf8Multilang::GetLangIndex(languages::GetCurrentNorm()), StringUtf8Multilang::kInternationalCode, @@ -45,9 +51,6 @@ void GetNames(FeatureID const & id, StringUtf8Multilang const & src, string & pr auto primaryIndex = primaryCodes.size(); auto secondaryIndex = secondaryCodes.size(); - primary.clear(); - secondary.clear(); - auto const findAndSet = [](vector const & langs, int8_t const code, string const & name, size_t & bestIndex, string & outName) { diff --git a/indexer/indexer_tests/feature_names_test.cpp b/indexer/indexer_tests/feature_names_test.cpp new file mode 100644 index 0000000000..bc44e5bcec --- /dev/null +++ b/indexer/indexer_tests/feature_names_test.cpp @@ -0,0 +1,39 @@ +#include "testing/testing.hpp" + +#include "indexer/features_vector.hpp" +#include "indexer/index.hpp" +#include "indexer/mwm_set.hpp" + +#include "platform/local_country_file.hpp" + +using namespace platform; + +namespace +{ +UNIT_TEST(GetFeatureNames) +{ + LocalCountryFile localFile = LocalCountryFile::MakeForTesting("minsk-pass"); + + Index index; + auto result = index.RegisterMap(localFile); + TEST_EQUAL(result.second, MwmSet::RegResult::Success, ()); + + auto const & id = result.first; + MwmSet::MwmHandle handle = index.GetMwmHandleById(id); + TEST(handle.IsAlive(), ()); + + auto const * value = handle.GetValue(); + FeaturesVector fv(value->m_cont, value->GetHeader(), value->m_table.get()); + string primary, secondary, readable; + + fv.ForEach([&](FeatureType & ft, uint32_t /* index */) + { + ft.GetPreferredNames(primary, secondary); + if (!secondary.empty()) + { + ft.GetReadableName(readable); + TEST_EQUAL(secondary, readable, ()); + } + }); +} +} // namespace diff --git a/indexer/indexer_tests/indexer_tests.pro b/indexer/indexer_tests/indexer_tests.pro index 43abbd013a..68246f9005 100644 --- a/indexer/indexer_tests/indexer_tests.pro +++ b/indexer/indexer_tests/indexer_tests.pro @@ -28,6 +28,7 @@ SOURCES += \ drules_selector_parser_test.cpp \ editable_map_object_test.cpp \ feature_metadata_test.cpp \ + feature_names_test.cpp \ feature_xml_test.cpp \ features_offsets_table_test.cpp \ features_vector_test.cpp \