Skip to content

Commit 2cff1e2

Browse files
committed
Reduce UI draw stalls from LLSpellChecker singleton via simpleton
1 parent ad8dc13 commit 2cff1e2

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

indra/llui/llspellcheck.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,13 @@ static const std::string DICT_FILE_USER = "user_dictionaries.xml";
4242
LLSpellChecker::settings_change_signal_t LLSpellChecker::sSettingsChangeSignal;
4343

4444
LLSpellChecker::LLSpellChecker()
45-
: mHunspell(NULL)
4645
{
46+
// Load initial dictionary information
47+
refreshDictionaryMap();
4748
}
4849

4950
LLSpellChecker::~LLSpellChecker()
5051
{
51-
delete mHunspell;
52-
}
53-
54-
void LLSpellChecker::initSingleton()
55-
{
56-
// Load initial dictionary information
57-
refreshDictionaryMap();
5852
}
5953

6054
bool LLSpellChecker::checkSpelling(const std::string& word) const
@@ -300,8 +294,7 @@ void LLSpellChecker::initHunspell(const std::string& dict_language)
300294
{
301295
if (mHunspell)
302296
{
303-
delete mHunspell;
304-
mHunspell = NULL;
297+
mHunspell.reset();
305298
mDictLanguage.clear();
306299
mDictFile.clear();
307300
mIgnoreList.clear();
@@ -322,11 +315,11 @@ void LLSpellChecker::initHunspell(const std::string& dict_language)
322315
const std::string filename_dic = dict_entry["name"].asString() + ".dic";
323316
if ( (gDirUtilp->fileExists(user_path + filename_aff)) && (gDirUtilp->fileExists(user_path + filename_dic)) )
324317
{
325-
mHunspell = new Hunspell((user_path + filename_aff).c_str(), (user_path + filename_dic).c_str());
318+
mHunspell = std::make_unique<Hunspell>((user_path + filename_aff).c_str(), (user_path + filename_dic).c_str());
326319
}
327320
else if ( (gDirUtilp->fileExists(app_path + filename_aff)) && (gDirUtilp->fileExists(app_path + filename_dic)) )
328321
{
329-
mHunspell = new Hunspell((app_path + filename_aff).c_str(), (app_path + filename_dic).c_str());
322+
mHunspell = std::make_unique<Hunspell>((app_path + filename_aff).c_str(), (app_path + filename_dic).c_str());
330323
}
331324
if (!mHunspell)
332325
{

indra/llui/llspellcheck.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,19 @@
3434

3535
class Hunspell;
3636

37-
class LLSpellChecker : public LLSingleton<LLSpellChecker>
37+
class LLSpellChecker : public LLSimpleton<LLSpellChecker>
3838
{
39-
LLSINGLETON(LLSpellChecker);
39+
public:
40+
LLSpellChecker();
4041
~LLSpellChecker();
4142

42-
public:
4343
void addToCustomDictionary(const std::string& word);
4444
void addToIgnoreList(const std::string& word);
4545
bool checkSpelling(const std::string& word) const;
4646
S32 getSuggestions(const std::string& word, std::vector<std::string>& suggestions) const;
4747
protected:
4848
void addToDictFile(const std::string& dict_path, const std::string& word);
4949
void initHunspell(const std::string& dict_language);
50-
void initSingleton() override;
5150

5251
public:
5352
typedef std::list<std::string> dict_list_t;
@@ -77,7 +76,7 @@ class LLSpellChecker : public LLSingleton<LLSpellChecker>
7776
static boost::signals2::connection setSettingsChangeCallback(const settings_change_signal_t::slot_type& cb);
7877

7978
protected:
80-
Hunspell* mHunspell;
79+
std::unique_ptr<Hunspell> mHunspell;
8180
std::string mDictLanguage;
8281
std::string mDictFile;
8382
dict_list_t mDictSecondary;

indra/llui/llui.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "llmenubutton.h"
5555
#include "llloadingindicator.h"
5656
#include "llwindow.h"
57+
#include "llspellcheck.h"
5758

5859
// for registration
5960
#include "llfiltereditor.h"
@@ -157,6 +158,7 @@ mRootView(NULL),
157158
mHelpImpl(NULL)
158159
{
159160
LLRender2D::createInstance(image_provider);
161+
LLSpellChecker::createInstance();
160162

161163
if ((get_ptr_in_map(mSettingGroups, std::string("config")) == NULL) ||
162164
(get_ptr_in_map(mSettingGroups, std::string("floater")) == NULL) ||
@@ -198,6 +200,7 @@ mHelpImpl(NULL)
198200

199201
LLUI::~LLUI()
200202
{
203+
LLSpellChecker::deleteSingleton();
201204
LLRender2D::deleteSingleton();
202205
}
203206

indra/newview/llappviewer.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,20 @@ bool LLAppViewer::init()
806806
LLUIImageList::getInstance(),
807807
ui_audio_callback,
808808
deferred_ui_audio_callback);
809+
810+
if (gSavedSettings.getBOOL("SpellCheck"))
811+
{
812+
std::list<std::string> dict_list;
813+
std::string dict_setting = gSavedSettings.getString("SpellCheckDictionary");
814+
boost::split(dict_list, dict_setting, boost::is_any_of(std::string(",")));
815+
if (!dict_list.empty())
816+
{
817+
LLSpellChecker::setUseSpellCheck(dict_list.front());
818+
dict_list.pop_front();
819+
LLSpellChecker::instance().setSecondaryDictionaries(dict_list);
820+
}
821+
}
822+
809823
LL_INFOS("InitInfo") << "UI initialized." << LL_ENDL ;
810824

811825
// NOW LLUI::getLanguage() should work. gDirUtilp must know the language
@@ -1611,7 +1625,7 @@ bool LLAppViewer::doFrame()
16111625

16121626
{
16131627
LL_PROFILE_ZONE_NAMED_CATEGORY_APP("df gMeshRepo");
1614-
gMeshRepo.update() ;
1628+
gMeshRepo.update() ;
16151629
}
16161630

16171631
if(!total_work_pending) //pause texture fetching threads if nothing to process.
@@ -2799,19 +2813,6 @@ bool LLAppViewer::initConfiguration()
27992813
gSavedSettings.getString("Language"));
28002814
}
28012815

2802-
if (gSavedSettings.getBOOL("SpellCheck"))
2803-
{
2804-
std::list<std::string> dict_list;
2805-
std::string dict_setting = gSavedSettings.getString("SpellCheckDictionary");
2806-
boost::split(dict_list, dict_setting, boost::is_any_of(std::string(",")));
2807-
if (!dict_list.empty())
2808-
{
2809-
LLSpellChecker::setUseSpellCheck(dict_list.front());
2810-
dict_list.pop_front();
2811-
LLSpellChecker::instance().setSecondaryDictionaries(dict_list);
2812-
}
2813-
}
2814-
28152816
if (gNonInteractive)
28162817
{
28172818
tempSetControl("AllowMultipleViewers", "true");

0 commit comments

Comments
 (0)