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

View File

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