Changeset 237357 in webkit
- Timestamp:
- Oct 23, 2018 11:02:32 AM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r237355 r237357 1 2018-10-23 Antti Koivisto <antti@apple.com> 2 3 topPrivatelyControlledDomain is slow 4 https://bugs.webkit.org/show_bug.cgi?id=190792 5 6 Reviewed by Alex Christensen. 7 8 It calls into some slowish CFNetwork code and ends up showing up in profiles. 9 10 * platform/mac/PublicSuffixMac.mm: 11 (WebCore::topPrivatelyControlledDomain): 12 13 Add a cache that avoids calls into frameworks. 14 1 15 2018-10-23 Chris Dumez <cdumez@apple.com> 2 16 -
trunk/Source/WebCore/platform/mac/PublicSuffixMac.mm
r232501 r237357 32 32 #import "WebCoreNSURLExtras.h" 33 33 #import <pal/spi/cf/CFNetworkSPI.h> 34 #import <wtf/HashMap.h> 35 #import <wtf/text/StringHash.h> 34 36 35 37 namespace WebCore { … … 44 46 String topPrivatelyControlledDomain(const String& domain) 45 47 { 46 if ( URL::hostIsIPAddress(domain))48 if (domain.isEmpty() || !domain.isAllASCII()) 47 49 return domain; 48 50 49 if (!domain.isAllASCII()) 50 return domain; 51 52 const auto& lowercaseDomain = domain.convertToASCIILowercase(); 53 if (lowercaseDomain == "localhost") 54 return lowercaseDomain; 51 static NeverDestroyed<HashMap<String, String, ASCIICaseInsensitiveHash>> cache; 52 static Lock cacheLock; 55 53 56 size_t separatorPosition; 57 for (unsigned labelStart = 0; (separatorPosition = lowercaseDomain.find('.', labelStart)) != notFound; labelStart = separatorPosition + 1) { 58 if (isPublicSuffix(lowercaseDomain.substring(separatorPosition + 1))) 59 return lowercaseDomain.substring(labelStart); 60 } 61 return String(); 54 auto isolatedDomain = domain.isolatedCopy(); 55 56 auto locker = holdLock(cacheLock); 57 58 constexpr auto maximumSizeToPreventUnlimitedGrowth = 128; 59 if (cache.get().size() == maximumSizeToPreventUnlimitedGrowth) 60 cache.get().clear(); 61 62 return cache.get().ensure(isolatedDomain, [&isolatedDomain] { 63 const auto lowercaseDomain = isolatedDomain.convertToASCIILowercase(); 64 if (lowercaseDomain == "localhost") 65 return lowercaseDomain; 66 67 if (URL::hostIsIPAddress(lowercaseDomain)) 68 return lowercaseDomain; 69 70 size_t separatorPosition; 71 for (unsigned labelStart = 0; (separatorPosition = lowercaseDomain.find('.', labelStart)) != notFound; labelStart = separatorPosition + 1) { 72 if (isPublicSuffix(lowercaseDomain.substring(separatorPosition + 1))) 73 return lowercaseDomain.substring(labelStart); 74 } 75 return String(); 76 }).iterator->value.isolatedCopy(); 62 77 } 63 78
Note: See TracChangeset
for help on using the changeset viewer.