diff --git a/coding/file_container.cpp b/coding/file_container.cpp index 35f5733323..ebe1fbaa51 100644 --- a/coding/file_container.cpp +++ b/coding/file_container.cpp @@ -3,6 +3,8 @@ #include "coding/write_to_sink.hpp" #include "coding/internal/file_data.hpp" +#include "std/cstring.hpp" + #ifndef OMIM_OS_WINDOWS #include #include @@ -122,7 +124,7 @@ void MappedFile::Open(string const & fName) #else m_fd = open(fName.c_str(), O_RDONLY | O_NONBLOCK); if (m_fd == -1) - MYTHROW(Reader::OpenException, ("Can't open file:", fName)); + MYTHROW(Reader::OpenException, ("Can't open file:", fName, ", reason:", strerror(errno))); #endif } diff --git a/indexer/index.cpp b/indexer/index.cpp index 592e8d6cdb..516e460196 100644 --- a/indexer/index.cpp +++ b/indexer/index.cpp @@ -17,27 +17,17 @@ using platform::LocalCountryFile; ////////////////////////////////////////////////////////////////////////////////// MwmValue::MwmValue(LocalCountryFile const & localFile) - : m_cont(platform::GetCountryReader(localFile, MapOptions::Map)), - m_file(localFile), - m_table(0) + : m_cont(platform::GetCountryReader(localFile, MapOptions::Map)), m_file(localFile) { m_factory.Load(m_cont); -} -void MwmValue::SetTable(MwmInfoEx & info) -{ auto const version = GetHeader().GetFormat(); if (version < version::Format::v5) - return; - - if (!info.m_table) - { - if (version == version::Format::v5) - info.m_table = feature::FeaturesOffsetsTable::CreateIfNotExistsAndLoad(m_file, m_cont); - else - info.m_table = feature::FeaturesOffsetsTable::Load(m_cont); - } - m_table = info.m_table.get(); + ; + else if (version == version::Format::v5) + m_table = feature::FeaturesOffsetsTable::CreateIfNotExistsAndLoad(m_file, m_cont); + else + m_table = feature::FeaturesOffsetsTable::Load(m_cont); } ////////////////////////////////////////////////////////////////////////////////// @@ -52,7 +42,7 @@ unique_ptr Index::CreateInfo(platform::LocalCountryFile const & localFi if (!h.IsMWMSuitable()) return nullptr; - unique_ptr info(new MwmInfoEx()); + auto info = make_unique(); info->m_limitRect = h.GetBounds(); pair const scaleR = h.GetScaleRange(); @@ -60,7 +50,7 @@ unique_ptr Index::CreateInfo(platform::LocalCountryFile const & localFi info->m_maxScale = static_cast(scaleR.second); info->m_version = value.GetMwmVersion(); - return unique_ptr(move(info)); + return info; } unique_ptr Index::CreateValue(MwmInfo & info) const @@ -68,7 +58,6 @@ unique_ptr Index::CreateValue(MwmInfo & info) const // Create a section with rank table if it does not exist. platform::LocalCountryFile const & localFile = info.GetLocalFile(); unique_ptr p(new MwmValue(localFile)); - p->SetTable(dynamic_cast(info)); ASSERT(p->GetHeader().IsMWMSuitable(), ()); return unique_ptr(move(p)); } @@ -85,11 +74,11 @@ bool Index::DeregisterMap(CountryFile const & countryFile) { return Deregister(c ////////////////////////////////////////////////////////////////////////////////// Index::FeaturesLoaderGuard::FeaturesLoaderGuard(Index const & parent, MwmId const & id) - : m_handle(parent.GetMwmHandleById(id)), - /// @note This guard is suitable when mwm is loaded - m_vector(m_handle.GetValue()->m_cont, - m_handle.GetValue()->GetHeader(), - m_handle.GetValue()->m_table) + : m_handle(parent.GetMwmHandleById(id)) + , + /// @note This guard is suitable when mwm is loaded + m_vector(m_handle.GetValue()->m_cont, m_handle.GetValue()->GetHeader(), + m_handle.GetValue()->m_table.get()) { } diff --git a/indexer/index.hpp b/indexer/index.hpp index 7e4fa77153..09d61b9f1d 100644 --- a/indexer/index.hpp +++ b/indexer/index.hpp @@ -20,23 +20,15 @@ #include "std/utility.hpp" #include "std/vector.hpp" - -class MwmInfoEx : public MwmInfo -{ -public: - unique_ptr m_table; -}; - class MwmValue : public MwmSet::MwmValueBase { public: FilesContainerR const m_cont; IndexFactory m_factory; platform::LocalCountryFile const m_file; - feature::FeaturesOffsetsTable const * m_table; + unique_ptr m_table; explicit MwmValue(platform::LocalCountryFile const & localFile); - void SetTable(MwmInfoEx & info); inline feature::DataHeader const & GetHeader() const { return m_factory.GetHeader(); } inline version::MwmVersion const & GetMwmVersion() const { return m_factory.GetMwmVersion(); } @@ -97,7 +89,7 @@ private: covering::IntervalsT const & interval = cov.Get(lastScale); // Prepare features reading. - FeaturesVector const fv(pValue->m_cont, header, pValue->m_table); + FeaturesVector const fv(pValue->m_cont, header, pValue->m_table.get()); ScaleIndex index(pValue->m_cont.GetReader(INDEX_FILE_TAG), pValue->m_factory); @@ -224,7 +216,8 @@ public: if (handle.IsAlive()) { MwmValue const * pValue = handle.GetValue(); - FeaturesVector const featureReader(pValue->m_cont, pValue->GetHeader(), pValue->m_table); + FeaturesVector const featureReader(pValue->m_cont, pValue->GetHeader(), + pValue->m_table.get()); do { osm::Editor::FeatureStatus const fts = editor.GetFeatureStatus(id, fidIter->m_index); diff --git a/indexer/indexer_tests/features_vector_test.cpp b/indexer/indexer_tests/features_vector_test.cpp index b991764899..975face9e0 100644 --- a/indexer/indexer_tests/features_vector_test.cpp +++ b/indexer/indexer_tests/features_vector_test.cpp @@ -59,7 +59,7 @@ UNIT_TEST(FeaturesVectorTest_ParseMetadata) TEST(handle.IsAlive(), ()); auto const * value = handle.GetValue(); - FeaturesVector fv(value->m_cont, value->GetHeader(), value->m_table); + FeaturesVector fv(value->m_cont, value->GetHeader(), value->m_table.get()); map actual; fv.ForEach([&](FeatureType & ft, uint32_t index) diff --git a/indexer/mwm_set.hpp b/indexer/mwm_set.hpp index f7ab054fa7..9423077689 100644 --- a/indexer/mwm_set.hpp +++ b/indexer/mwm_set.hpp @@ -112,10 +112,7 @@ public: }; public: - // Default value 32=2^5 was from the very begining. - // Later, we replaced my::Cache with the std::deque, but forgot to change - // logarithm constant 5 with actual size 32. Now it's fixed. - explicit MwmSet(size_t cacheSize = 32) : m_cacheSize(cacheSize) {} + explicit MwmSet(size_t cacheSize = 64) : m_cacheSize(cacheSize) {} virtual ~MwmSet() = default; class MwmValueBase diff --git a/search/mwm_context.cpp b/search/mwm_context.cpp index b89575d420..58e999994e 100644 --- a/search/mwm_context.cpp +++ b/search/mwm_context.cpp @@ -12,7 +12,7 @@ void CoverRect(m2::RectD const & rect, int scale, covering::IntervalsT & result) MwmContext::MwmContext(MwmSet::MwmHandle handle) : m_handle(move(handle)) , m_value(*m_handle.GetValue()) - , m_vector(m_value.m_cont, m_value.GetHeader(), m_value.m_table) + , m_vector(m_value.m_cont, m_value.GetHeader(), m_value.m_table.get()) , m_index(m_value.m_cont.GetReader(INDEX_FILE_TAG), m_value.m_factory) { }