From c64c35234e87cab62e788cd4eee2c2236f159dcc Mon Sep 17 00:00:00 2001 From: vng Date: Wed, 22 Jul 2015 17:35:33 +0300 Subject: [PATCH] Review fixes 2. --- indexer/feature_processor.hpp | 4 +-- indexer/features_offsets_table.cpp | 6 ++--- indexer/index.cpp | 12 ++++----- indexer/index_builder.cpp | 4 +-- indexer/index_builder.hpp | 4 +-- indexer/indexer_tests/index_builder_test.cpp | 4 +-- indexer/scale_index_builder.hpp | 4 +-- indexer/search_index_builder.cpp | 12 ++++----- map/benchmark_tool/features_loading.cpp | 26 ++++++++++---------- platform/platform_tests/platform_test.cpp | 2 +- routing/osrm2feature_map.cpp | 5 ++-- 11 files changed, 41 insertions(+), 42 deletions(-) diff --git a/indexer/feature_processor.hpp b/indexer/feature_processor.hpp index 91710f04cc..08b1a1d8b0 100644 --- a/indexer/feature_processor.hpp +++ b/indexer/feature_processor.hpp @@ -16,8 +16,8 @@ namespace feature template void ForEachFromDat(ModelReaderPtr reader, ToDo & toDo) { - FeaturesVectorTest featuresV((FilesContainerR(reader))); - featuresV.GetVector().ForEach(ref(toDo)); + FeaturesVectorTest features((FilesContainerR(reader))); + features.GetVector().ForEach(ref(toDo)); } template diff --git a/indexer/features_offsets_table.cpp b/indexer/features_offsets_table.cpp index 7ef0f64bf7..f06c4d75d7 100644 --- a/indexer/features_offsets_table.cpp +++ b/indexer/features_offsets_table.cpp @@ -58,8 +58,7 @@ namespace feature // static unique_ptr FeaturesOffsetsTable::Load(string const & filePath) { - uint64_t size; - if (!GetPlatform().GetFileSizeByFullPath(filePath, size)) + if (!GetPlatform().IsFileExistsByFullPath(filePath)) return unique_ptr(); return LoadImpl(filePath); } @@ -70,8 +69,7 @@ namespace feature { string const offsetsFilePath = CountryIndexes::GetPath(localFile, CountryIndexes::Index::Offsets); - uint64_t size; - if (GetPlatform().GetFileSizeByFullPath(offsetsFilePath, size)) + if (GetPlatform().IsFileExistsByFullPath(offsetsFilePath)) return LoadImpl(offsetsFilePath); LOG(LINFO, ("Creating features offset table file", offsetsFilePath)); diff --git a/indexer/index.cpp b/indexer/index.cpp index c34db7002a..b1c7289fce 100644 --- a/indexer/index.cpp +++ b/indexer/index.cpp @@ -24,12 +24,12 @@ MwmValue::MwmValue(LocalCountryFile const & localFile) void MwmValue::SetTable(MwmInfoEx & info) { - if (GetHeader().GetFormat() >= version::v5) - { - if (!info.m_table) - info.m_table = feature::FeaturesOffsetsTable::CreateIfNotExistsAndLoad(m_cont); - m_table = info.m_table.get(); - } + if (GetHeader().GetFormat() < version::v5) + return; + + if (!info.m_table) + info.m_table = feature::FeaturesOffsetsTable::CreateIfNotExistsAndLoad(m_cont); + m_table = info.m_table.get(); } ////////////////////////////////////////////////////////////////////////////////// diff --git a/indexer/index_builder.cpp b/indexer/index_builder.cpp index 984ff530c0..e5caf8afce 100644 --- a/indexer/index_builder.cpp +++ b/indexer/index_builder.cpp @@ -14,10 +14,10 @@ namespace indexer { string const idxFileName(tmpFile + GEOM_INDEX_TMP_EXT); { - FeaturesVectorTest featuresV(datFile); + FeaturesVectorTest features(datFile); FileWriter writer(idxFileName); - BuildIndex(featuresV.GetHeader(), featuresV.GetVector(), writer, tmpFile); + BuildIndex(features.GetHeader(), features.GetVector(), writer, tmpFile); } FilesContainerW(datFile, FileWriter::OP_WRITE_EXISTING).Write(idxFileName, INDEX_FILE_TAG); diff --git a/indexer/index_builder.hpp b/indexer/index_builder.hpp index 364c81a02c..db4ef9f642 100644 --- a/indexer/index_builder.hpp +++ b/indexer/index_builder.hpp @@ -6,14 +6,14 @@ namespace indexer { template -void BuildIndex(feature::DataHeader const & header, TFeaturesVector const & featuresV, +void BuildIndex(feature::DataHeader const & header, TFeaturesVector const & features, TWriter & writer, string const & tmpFilePrefix) { LOG(LINFO, ("Building scale index.")); uint64_t indexSize; { SubWriter subWriter(writer); - covering::IndexScales(header, featuresV, subWriter, tmpFilePrefix); + covering::IndexScales(header, features, subWriter, tmpFilePrefix); indexSize = subWriter.Size(); } LOG(LINFO, ("Built scale index. Size =", indexSize)); diff --git a/indexer/indexer_tests/index_builder_test.cpp b/indexer/indexer_tests/index_builder_test.cpp index 6fe4bd68a5..f192f6ee8d 100644 --- a/indexer/indexer_tests/index_builder_test.cpp +++ b/indexer/indexer_tests/index_builder_test.cpp @@ -26,10 +26,10 @@ UNIT_TEST(BuildIndexTest) // Build index. vector serialIndex; { - FeaturesVectorTest featuresV(originalContainer); + FeaturesVectorTest features(originalContainer); MemWriter > serialWriter(serialIndex); - indexer::BuildIndex(featuresV.GetHeader(), featuresV.GetVector(), serialWriter, "build_index_test"); + indexer::BuildIndex(features.GetHeader(), features.GetVector(), serialWriter, "build_index_test"); } // Create a new mwm file. diff --git a/indexer/scale_index_builder.hpp b/indexer/scale_index_builder.hpp index 94376b8c29..18b04bcf7b 100644 --- a/indexer/scale_index_builder.hpp +++ b/indexer/scale_index_builder.hpp @@ -193,7 +193,7 @@ private: }; template -void IndexScales(feature::DataHeader const & header, TFeaturesVector const & featuresV, +void IndexScales(feature::DataHeader const & header, TFeaturesVector const & features, TWriter & writer, string const & tmpFilePrefix) { // TODO: Make scale bucketing dynamic. @@ -212,7 +212,7 @@ void IndexScales(feature::DataHeader const & header, TFeaturesVector const & fea TSorter sorter(1024 * 1024 /* bufferBytes */, tmpFilePrefix + CELL2FEATURE_TMP_EXT, out); vector featuresInBucket(bucketsCount); vector cellsInBucket(bucketsCount); - featuresV.ForEach(FeatureCoverer(header, sorter, featuresInBucket, cellsInBucket)); + features.ForEach(FeatureCoverer(header, sorter, featuresInBucket, cellsInBucket)); sorter.SortAndFinish(); for (uint32_t bucket = 0; bucket < bucketsCount; ++bucket) diff --git a/indexer/search_index_builder.cpp b/indexer/search_index_builder.cpp index 7ca3488fa1..67dc33cc95 100644 --- a/indexer/search_index_builder.cpp +++ b/indexer/search_index_builder.cpp @@ -365,8 +365,8 @@ void AddFeatureNameIndexPairs(FilesContainerR const & container, CategoriesHolder & categoriesHolder, StringsFile & stringsFile) { - FeaturesVectorTest featuresV(container); - feature::DataHeader const & header = featuresV.GetHeader(); + FeaturesVectorTest features(container); + feature::DataHeader const & header = features.GetHeader(); ValueBuilder valueBuilder; @@ -374,7 +374,7 @@ void AddFeatureNameIndexPairs(FilesContainerR const & container, if (header.GetType() == feature::DataHeader::world) synonyms.reset(new SynonymsHolder(GetPlatform().WritablePathForFile(SYNONYMS_FILE))); - featuresV.GetVector().ForEach(FeatureInserter>( + features.GetVector().ForEach(FeatureInserter>( synonyms.get(), stringsFile, categoriesHolder, header.GetScaleRange(), valueBuilder)); } @@ -382,8 +382,8 @@ void BuildSearchIndex(FilesContainerR const & cont, CategoriesHolder const & cat Writer & writer, string const & tmpFilePath) { { - FeaturesVectorTest featuresV(cont); - feature::DataHeader const & header = featuresV.GetHeader(); + FeaturesVectorTest features(cont); + feature::DataHeader const & header = features.GetHeader(); serial::CodingParams cp(search::GetCPForTrie(header.GetDefCodingParams())); ValueBuilder valueBuilder(cp); @@ -394,7 +394,7 @@ void BuildSearchIndex(FilesContainerR const & cont, CategoriesHolder const & cat StringsFile names(tmpFilePath); - featuresV.GetVector().ForEach(FeatureInserter>( + features.GetVector().ForEach(FeatureInserter>( synonyms.get(), names, catHolder, header.GetScaleRange(), valueBuilder)); names.EndAdding(); diff --git a/map/benchmark_tool/features_loading.cpp b/map/benchmark_tool/features_loading.cpp index 8f7d711c07..ddb1c952a6 100644 --- a/map/benchmark_tool/features_loading.cpp +++ b/map/benchmark_tool/features_loading.cpp @@ -58,9 +58,9 @@ namespace }; void RunBenchmark(model::FeaturesFetcher const & src, m2::RectD const & rect, - pair const & scaleR, AllResult & res) + pair const & scaleRange, AllResult & res) { - ASSERT_LESS_OR_EQUAL ( scaleR.first, scaleR.second, () ); + ASSERT_LESS_OR_EQUAL(scaleRange.first, scaleRange.second, ()); vector rects; rects.push_back(rect); @@ -74,7 +74,7 @@ namespace bool doDivide = true; int const scale = scales::GetScaleLevel(r); - if (scale >= scaleR.first) + if (scale >= scaleRange.first) { acc.Reset(scale); @@ -85,7 +85,7 @@ namespace doDivide = !acc.IsEmpty(); } - if (doDivide && scale < scaleR.second) + if (doDivide && scale < scaleRange.second) { m2::RectD r1, r2; r.DivideByGreaterSize(r1, r2); @@ -96,7 +96,7 @@ namespace } } -void RunFeaturesLoadingBenchmark(string const & file, pair scaleR, AllResult & res) +void RunFeaturesLoadingBenchmark(string const & file, pair scaleRange, AllResult & res) { string fileName = file; my::GetNameFromFullPath(fileName); @@ -110,17 +110,17 @@ void RunFeaturesLoadingBenchmark(string const & file, pair scaleR, All if (r.second != MwmSet::RegResult::Success) return; - uint8_t const minS = r.first.GetInfo()->m_minScale; - uint8_t const maxS = r.first.GetInfo()->m_maxScale; - if (minS > scaleR.first) - scaleR.first = minS; - if (maxS < scaleR.second) - scaleR.second = maxS; + uint8_t const minScale = r.first.GetInfo()->m_minScale; + uint8_t const maxScale = r.first.GetInfo()->m_maxScale; + if (minScale > scaleRange.first) + scaleRange.first = minScale; + if (maxScale < scaleRange.second) + scaleRange.second = maxScale; - if (scaleR.first > scaleR.second) + if (scaleRange.first > scaleRange.second) return; - RunBenchmark(src, r.first.GetInfo()->m_limitRect, scaleR, res); + RunBenchmark(src, r.first.GetInfo()->m_limitRect, scaleRange, res); } } diff --git a/platform/platform_tests/platform_test.cpp b/platform/platform_tests/platform_test.cpp index c620f0f48b..bfd16357dd 100644 --- a/platform/platform_tests/platform_test.cpp +++ b/platform/platform_tests/platform_test.cpp @@ -164,7 +164,7 @@ UNIT_TEST(GetFileSize) Platform & pl = GetPlatform(); uint64_t size = 123141; TEST(!pl.GetFileSizeByName("adsmngfuwrbfyfwe", size), ()); - TEST(!Platform::GetFileSizeByFullPath("adsmngfuwrbfyfwe", size), ()); + TEST(!pl.IsFileExistsByFullPath("adsmngfuwrbfyfwe"), ()); { FileWriter testFile(TEST_FILE_NAME); diff --git a/routing/osrm2feature_map.cpp b/routing/osrm2feature_map.cpp index bee4c781fa..3b3751ea3c 100644 --- a/routing/osrm2feature_map.cpp +++ b/routing/osrm2feature_map.cpp @@ -354,9 +354,10 @@ void OsrmFtSegBackwardIndex::Save(string const & nodesFileName, string const & b bool OsrmFtSegBackwardIndex::Load(string const & nodesFileName, string const & bitsFileName) { - uint64_t size; - if (!GetPlatform().GetFileSizeByFullPath(nodesFileName, size) || !GetPlatform().GetFileSizeByFullPath(bitsFileName, size)) + Platform & pl = GetPlatform(); + if (!pl.IsFileExistsByFullPath(nodesFileName) || !pl.IsFileExistsByFullPath(bitsFileName)) return false; + m_mappedBits.reset(new MmapReader(bitsFileName)); {