[GTK] WebKitWebProcess at 100% CPU loading hyphenation dictionaries
[WebKit-https.git] / Source / WebCore / platform / text / hyphen / HyphenationLibHyphen.cpp
index f497e5b..f7b8011 100644 (file)
@@ -31,6 +31,8 @@
 
 #include "FileSystem.h"
 #include <hyphen.h>
+#include <limits>
+#include <stdlib.h>
 #include <wtf/HashMap.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/TinyLRUCache.h>
@@ -62,8 +64,14 @@ static String extractLocaleFromDictionaryFilePath(const String& filePath)
 
 static void scanDirectoryForDicionaries(const char* directoryPath, HashMap<AtomicString, Vector<String>>& availableLocales)
 {
-    for (const auto& filePath : listDirectory(directoryPath, "hyph_*.dic")) {
+    for (auto& filePath : listDirectory(directoryPath, "hyph_*.dic")) {
         String locale = extractLocaleFromDictionaryFilePath(filePath).convertToASCIILowercase();
+
+        char normalizedPath[PATH_MAX];
+        if (!realpath(fileSystemRepresentation(filePath).data(), normalizedPath))
+            continue;
+
+        filePath = stringFromFileSystemRepresentation(normalizedPath);
         availableLocales.add(locale, Vector<String>()).iterator->value.append(filePath);
 
         String localeReplacingUnderscores = String(locale);
@@ -176,9 +184,9 @@ template<>
 class TinyLRUCachePolicy<AtomicString, RefPtr<WebCore::HyphenationDictionary>>
 {
 public:
-    static TinyLRUCache<AtomicString, RefPtr<WebCore::HyphenationDictionary>>& cache()
+    static TinyLRUCache<AtomicString, RefPtr<WebCore::HyphenationDictionary>, 32>& cache()
     {
-        static NeverDestroyed<TinyLRUCache<AtomicString, RefPtr<WebCore::HyphenationDictionary>>> cache;
+        static NeverDestroyed<TinyLRUCache<AtomicString, RefPtr<WebCore::HyphenationDictionary>, 32>> cache;
         return cache;
     }