Review fixes

This commit is contained in:
VladiMihaylenko 2017-10-11 15:54:09 +03:00 committed by Yuri Gorshenin
parent 0cfadf1cb5
commit 2740386ae5
3 changed files with 27 additions and 29 deletions

View file

@ -117,7 +117,7 @@ unique_ptr<FeatureType> Index::FeaturesLoaderGuard::GetOriginalFeatureByIndex(ui
{
auto feature = make_unique<FeatureType>();
if (!GetOriginalFeatureByIndex(index, *feature))
return unique_ptr<FeatureType>();
return {};
return feature;
}
@ -126,12 +126,12 @@ unique_ptr<FeatureType> Index::FeaturesLoaderGuard::GetOriginalOrEditedFeatureBy
{
auto feature = make_unique<FeatureType>();
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<FeatureType>();
return {};
return feature;
}

View file

@ -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 <algorithm>
#include <utility>
@ -214,32 +214,27 @@ void Storage::Defragmentation()
auto const ugcFilePath = GetUGCFilePath();
auto const tmpUGCFilePath = ugcFilePath + kTmpFileExtension;
FileReader r(ugcFilePath);
vector<uint8_t> 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<uint8_t> 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)
{

View file

@ -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(), ());
}