From 2740386ae59604105ab4d4b31b3d6687b24ef635 Mon Sep 17 00:00:00 2001 From: VladiMihaylenko Date: Wed, 11 Oct 2017 15:54:09 +0300 Subject: [PATCH] Review fixes --- indexer/index.cpp | 6 +++--- ugc/storage.cpp | 27 +++++++++++---------------- ugc/ugc_tests/storage_tests.cpp | 23 +++++++++++++---------- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/indexer/index.cpp b/indexer/index.cpp index 4ae66e8892..ac11d43c0d 100644 --- a/indexer/index.cpp +++ b/indexer/index.cpp @@ -117,7 +117,7 @@ unique_ptr Index::FeaturesLoaderGuard::GetOriginalFeatureByIndex(ui { auto feature = make_unique(); if (!GetOriginalFeatureByIndex(index, *feature)) - return unique_ptr(); + return {}; return feature; } @@ -126,12 +126,12 @@ unique_ptr Index::FeaturesLoaderGuard::GetOriginalOrEditedFeatureBy { auto feature = make_unique(); if (!m_handle.IsAlive()) - return feature; + return {}; MwmId const & id = m_handle.GetId(); ASSERT_NOT_EQUAL(m_editor.GetFeatureStatus(id, index), osm::Editor::FeatureStatus::Created, ()); if (!GetFeatureByIndex(index, *feature)) - return unique_ptr(); + return {}; return feature; } diff --git a/ugc/storage.cpp b/ugc/storage.cpp index fcdd25c0dd..613d4af48c 100644 --- a/ugc/storage.cpp +++ b/ugc/storage.cpp @@ -5,13 +5,13 @@ #include "indexer/feature_decl.hpp" #include "indexer/index.hpp" +#include "platform/platform.hpp" + #include "coding/file_name_utils.hpp" #include "coding/file_reader.hpp" #include "coding/file_writer.hpp" #include "coding/internal/file_data.hpp" -#include "platform/platform.hpp" - #include #include @@ -214,32 +214,27 @@ void Storage::Defragmentation() auto const ugcFilePath = GetUGCFilePath(); auto const tmpUGCFilePath = ugcFilePath + kTmpFileExtension; - FileReader r(ugcFilePath); - - vector buf; - uint64_t maxBufSize; - CHECK(GetUGCFileSize(maxBufSize), ()); - buf.resize(maxBufSize); - uint64_t actualBufSize = 0; try { + FileReader r(ugcFilePath); + FileWriter w(tmpUGCFilePath, FileWriter::Op::OP_APPEND); + uint64_t actualOffset = 0; for (size_t i = 0; i < indexesSize; ++i) { - CHECK_LESS_OR_EQUAL(actualBufSize, maxBufSize, ()); auto & index = m_UGCIndexes[i]; if (index.m_deleted) continue; auto const offset = index.m_offset; auto const size = UGCSizeAtIndex(i); - r.Read(offset, buf.data() + actualBufSize, size); - index.m_offset = actualBufSize; - actualBufSize += size; + vector buf; + buf.resize(size); + r.Read(offset, buf.data(), size); + w.Write(buf.data(), size); + index.m_offset = actualOffset; + actualOffset += size; } - - FileWriter w(tmpUGCFilePath); - w.Write(buf.data(), actualBufSize); } catch (FileReader::Exception const & exception) { diff --git a/ugc/ugc_tests/storage_tests.cpp b/ugc/ugc_tests/storage_tests.cpp index 4dd6a03491..fada557995 100644 --- a/ugc/ugc_tests/storage_tests.cpp +++ b/ugc/ugc_tests/storage_tests.cpp @@ -181,24 +181,27 @@ UNIT_TEST(StorageTests_DuplicatesAndDefragmentationSmoke) { auto & builder = MwmBuilder::Builder(); m2::PointD const point(1.0, 1.0); - builder.Build({TestCafe(point)}); - auto const id = builder.FeatureIdForCafeAtPoint(point); + builder.Build({TestCafe(point), TestRailway(point)}); + auto const cafeId = builder.FeatureIdForCafeAtPoint(point); + auto const railwayId = builder.FeatureIdForRailwayAtPoint(point); auto const first = MakeTestUGCUpdate(Time(chrono::hours(24 * 300))); auto const second = MakeTestUGCUpdate(Time(chrono::hours(24 * 100))); auto const third = MakeTestUGCUpdate(Time(chrono::hours(24 * 300))); auto const last = MakeTestUGCUpdate(Time(chrono::hours(24 * 100))); Storage storage(builder.GetIndex()); - storage.SetUGCUpdate(id, first); - storage.SetUGCUpdate(id, second); - storage.SetUGCUpdate(id, third); - storage.SetUGCUpdate(id, last); - TEST_EQUAL(last, storage.GetUGCUpdate(id), ()); - TEST_EQUAL(storage.GetIndexesForTesting().size(), 4, ()); + storage.SetUGCUpdate(cafeId, first); + storage.SetUGCUpdate(cafeId, second); + storage.SetUGCUpdate(cafeId, third); + storage.SetUGCUpdate(cafeId, last); + storage.SetUGCUpdate(railwayId, first); + TEST_EQUAL(last, storage.GetUGCUpdate(cafeId), ()); + TEST_EQUAL(storage.GetIndexesForTesting().size(), 5, ()); TEST_EQUAL(storage.GetNumberOfDeletedForTesting(), 3, ()); storage.Defragmentation(); - TEST_EQUAL(storage.GetIndexesForTesting().size(), 1, ()); + TEST_EQUAL(storage.GetIndexesForTesting().size(), 2, ()); TEST_EQUAL(storage.GetNumberOfDeletedForTesting(), 0, ()); - TEST_EQUAL(last, storage.GetUGCUpdate(id), ()); + TEST_EQUAL(last, storage.GetUGCUpdate(cafeId), ()); + TEST_EQUAL(first, storage.GetUGCUpdate(railwayId), ()); TEST(DeleteUGCFile(), ()); }