Don’t create NSSpellChecker tags until needed

This commit is contained in:
Allan Odgaard
2013-07-26 22:45:36 +02:00
parent cf3264cfc5
commit 34c44bd647
2 changed files with 18 additions and 7 deletions

View File

@@ -14,14 +14,17 @@ namespace ns
struct spelling_tag_t
{
spelling_tag_t () : _helper(new helper_t) { }
operator long int () const { return _helper->_tag; }
operator long int () const { return _helper->tag(); }
private:
struct PUBLIC helper_t
{
helper_t ();
~helper_t ();
long int tag ();
private:
long int _tag;
bool _did_setup = false;
};
std::shared_ptr<helper_t> _helper;

View File

@@ -5,20 +5,28 @@
namespace ns
{
spelling_tag_t::helper_t::helper_t ()
long int spelling_tag_t::helper_t::tag ()
{
_tag = [NSSpellChecker uniqueSpellDocumentTag];
if(!_did_setup)
{
_tag = [NSSpellChecker uniqueSpellDocumentTag];
_did_setup = true;
}
return _tag;
}
spelling_tag_t::helper_t::~helper_t ()
{
@autoreleasepool {
[[NSSpellChecker sharedSpellChecker] closeSpellDocumentWithTag:_tag];
if(_did_setup)
{
@autoreleasepool {
[[NSSpellChecker sharedSpellChecker] closeSpellDocumentWithTag:_tag];
}
}
}
template <typename _OutputIter>
_OutputIter spellcheck (char const* first, char const* last, std::string const& language, int tag, size_t offset, _OutputIter out)
_OutputIter spellcheck (char const* first, char const* last, std::string const& language, long int tag, size_t offset, _OutputIter out)
{
NSSpellChecker* spellChecker = [NSSpellChecker sharedSpellChecker];
NSString* lang = [NSString stringWithCxxString:language];