Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / source / core / tool / sharedstringpoolpurge.cxx
blob7b8749006efc0bfaca8ede9790852ad18625b091
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
11 #include <sharedstringpoolpurge.hxx>
13 #include <algorithm>
15 #include <vcl/svapp.hxx>
17 namespace sc
19 SharedStringPoolPurge::SharedStringPoolPurge()
20 : mTimer("SharedStringPoolPurge")
22 mTimer.SetPriority(TaskPriority::LOWEST);
23 mTimer.SetTimeout(10000); // 10 sec
24 mTimer.SetInvokeHandler(LINK(this, SharedStringPoolPurge, timerHandler));
27 SharedStringPoolPurge::~SharedStringPoolPurge() { cleanup(); }
29 void SharedStringPoolPurge::delayedPurge(const std::shared_ptr<svl::SharedStringPool>& pool)
31 if (std::find(mPoolsToPurge.begin(), mPoolsToPurge.end(), pool) == mPoolsToPurge.end())
33 mPoolsToPurge.push_back(pool);
34 SolarMutexGuard guard;
35 mTimer.Start();
39 void SharedStringPoolPurge::cleanup()
41 for (std::shared_ptr<svl::SharedStringPool>& pool : mPoolsToPurge)
43 if (pool.use_count() > 1)
44 pool->purge();
46 mPoolsToPurge.clear();
49 IMPL_LINK_NOARG(SharedStringPoolPurge, timerHandler, Timer*, void)
51 SolarMutexGuard guard;
52 mTimer.Stop();
53 cleanup();
56 } // namespace
58 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */