Retire a HashTable.

This commit is contained in:
2025-08-11 03:44:38 -04:00
parent f5a870a207
commit 91da2ff34b
2 changed files with 7 additions and 12 deletions

View File

@ -45,8 +45,7 @@ using namespace lout::unicode;
namespace dw {
HashTable <String, Hyphenator> *Hyphenator::hyphenators =
new HashTable <String, Hyphenator> (true, true);
std::map< std::string, std::unique_ptr< Hyphenator > > Hyphenator::hyphenators;
Hyphenator::Hyphenator (const char *patFile, const char *excFile, int pack)
{
@ -111,12 +110,10 @@ Hyphenator::~Hyphenator ()
Hyphenator *Hyphenator::getHyphenator (const char *lang)
{
String *langString = new String (lang);
auto &hyphenator= hyphenators[ lang ];
Hyphenator *hyphenator = hyphenators->get (langString);
if (hyphenator)
delete langString;
else {
if( not hyphenator )
{
using namespace std::literals::string_literals;
std::string patFile= DILLO_LIBDIR + "/hyphenation/"s + lang + ".pat";
std::string excFile= DILLO_LIBDIR + "/hyphenation"s + lang + ".exc";
@ -124,15 +121,14 @@ Hyphenator *Hyphenator::getHyphenator (const char *lang)
//printf ("Loading hyphenation patterns for language '%s' from '%s' and "
// "exceptions from '%s' ...\n", lang, patFile, excFile);
hyphenator = new Hyphenator (patFile.c_str(), excFile.c_str());
hyphenators->put (langString, hyphenator);
hyphenator= std::make_unique< Hyphenator >( patFile.c_str(), excFile.c_str() );
}
//lout::misc::StringBuffer sb;
//hyphenators->intoStringBuffer (&sb);
//printf ("%s\n", sb.getChars ());
return hyphenator;
return hyphenator.get();
}
void Hyphenator::insertPattern (TrieBuilder *trieBuilder, char *s)

View File

@ -85,8 +85,7 @@ class TrieBuilder {
class Hyphenator: public lout::object::Object
{
static lout::container::typed::HashTable
<lout::object::String, Hyphenator> *hyphenators;
static std::map< std::string, std::unique_ptr< Hyphenator > > hyphenators;
Trie *trie;
// Only instantiated when needed.