[generator] Move chunks vector in RawGenerator::GenerateFilteredFeatures.

Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
Viktor Govako 2022-04-28 23:55:59 +03:00
parent bbb432a599
commit fb2cb55e42
3 changed files with 16 additions and 17 deletions

View file

@ -240,24 +240,22 @@ bool RawGenerator::GenerateFilteredFeatures()
Stats stats(100 * m_threadsCount /* logCallCountThreshold */);
size_t element_pos = 0;
std::vector<OsmElement> elements(m_chunkSize);
while (sourceProcessor->TryRead(elements[element_pos]))
bool isEnd = false;
do
{
if (++element_pos != m_chunkSize)
continue;
std::vector<OsmElement> elements(m_chunkSize);
size_t idx = 0;
while (idx < m_chunkSize && sourceProcessor->TryRead(elements[idx]))
++idx;
stats.Log(elements, reader.Pos());
translators.Emit(elements);
isEnd = idx < m_chunkSize;
stats.Log(elements, reader.Pos(), isEnd/* forcePrint */);
for (auto & e : elements)
e.Clear();
if (isEnd)
elements.resize(idx);
translators.Emit(std::move(elements));
element_pos = 0;
}
elements.resize(element_pos);
stats.Log(elements, reader.Pos(), true /* forcePrint */);
translators.Emit(std::move(elements));
} while (!isEnd);
LOG(LINFO, ("Input was processed."));
if (!translators.Finish())

View file

@ -15,11 +15,12 @@ TranslatorsPool::TranslatorsPool(std::shared_ptr<TranslatorInterface> const & or
m_translators.Push(original->Clone());
}
void TranslatorsPool::Emit(std::vector<OsmElement> elements)
void TranslatorsPool::Emit(std::vector<OsmElement> && elements)
{
std::shared_ptr<TranslatorInterface> translator;
m_translators.WaitAndPop(translator);
m_threadPool.SubmitWork([&, translator, elements{std::move(elements)}]() mutable {
m_threadPool.SubmitWork([&, translator, elements = std::move(elements)]() mutable
{
for (auto & element : elements)
translator->Emit(element);

View file

@ -18,7 +18,7 @@ public:
explicit TranslatorsPool(std::shared_ptr<TranslatorInterface> const & original,
size_t threadCount);
void Emit(std::vector<OsmElement> elements);
void Emit(std::vector<OsmElement> && elements);
bool Finish();
private: