From 44a241b241af6453d4459c79b1a562c447e36636 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Thu, 28 Oct 2021 09:15:28 +0300 Subject: ICU: Update to version 70.1 --- thirdparty/icu4c/common/unifiedcache.h | 72 +++++++++++++++++----------------- 1 file changed, 36 insertions(+), 36 deletions(-) (limited to 'thirdparty/icu4c/common/unifiedcache.h') diff --git a/thirdparty/icu4c/common/unifiedcache.h b/thirdparty/icu4c/common/unifiedcache.h index a31998db20..07a734b8bd 100644 --- a/thirdparty/icu4c/common/unifiedcache.h +++ b/thirdparty/icu4c/common/unifiedcache.h @@ -53,11 +53,6 @@ class U_COMMON_API CacheKeyBase : public UObject { */ virtual CacheKeyBase *clone() const = 0; - /** - * Equality operator. - */ - virtual UBool operator == (const CacheKeyBase &other) const = 0; - /** * Create a new object for this key. Called by cache on cache miss. * createObject must add a reference to the object it returns. Note @@ -80,12 +75,19 @@ class U_COMMON_API CacheKeyBase : public UObject { */ virtual char *writeDescription(char *buffer, int32_t bufSize) const = 0; - /** - * Inequality operator. - */ - UBool operator != (const CacheKeyBase &other) const { - return !(*this == other); + friend inline bool operator==(const CacheKeyBase& lhs, + const CacheKeyBase& rhs) { + return lhs.equals(rhs); } + + friend inline bool operator!=(const CacheKeyBase& lhs, + const CacheKeyBase& rhs) { + return !lhs.equals(rhs); + } + + protected: + virtual bool equals(const CacheKeyBase& other) const = 0; + private: mutable UErrorCode fCreationStatus; mutable UBool fIsPrimary; @@ -105,7 +107,7 @@ class CacheKey : public CacheKeyBase { /** * The template parameter, T, determines the hash code returned. */ - virtual int32_t hashCode() const { + virtual int32_t hashCode() const override { const char *s = typeid(T).name(); return ustr_hashCharsN(s, static_cast(uprv_strlen(s))); } @@ -113,18 +115,19 @@ class CacheKey : public CacheKeyBase { /** * Use the value type, T, as the description. */ - virtual char *writeDescription(char *buffer, int32_t bufLen) const { + virtual char *writeDescription(char *buffer, int32_t bufLen) const override { const char *s = typeid(T).name(); uprv_strncpy(buffer, s, bufLen); buffer[bufLen - 1] = 0; return buffer; } + protected: /** * Two objects are equal if they are of the same type. */ - virtual UBool operator == (const CacheKeyBase &other) const { - return typeid(*this) == typeid(other); + virtual bool equals(const CacheKeyBase &other) const override { + return this == &other || typeid(*this) == typeid(other); } }; @@ -136,37 +139,34 @@ template class LocaleCacheKey : public CacheKey { protected: Locale fLoc; + virtual bool equals(const CacheKeyBase &other) const override { + if (!CacheKey::equals(other)) { + return false; + } + // We know this and other are of same class because equals() on + // CacheKey returned true. + return operator==(static_cast &>(other)); + } public: LocaleCacheKey(const Locale &loc) : fLoc(loc) {} LocaleCacheKey(const LocaleCacheKey &other) : CacheKey(other), fLoc(other.fLoc) { } virtual ~LocaleCacheKey() { } - virtual int32_t hashCode() const { + virtual int32_t hashCode() const override { return (int32_t)(37u * (uint32_t)CacheKey::hashCode() + (uint32_t)fLoc.hashCode()); } - virtual UBool operator == (const CacheKeyBase &other) const { - // reflexive - if (this == &other) { - return true; - } - if (!CacheKey::operator == (other)) { - return false; - } - // We know this and other are of same class because operator== on - // CacheKey returned true. - const LocaleCacheKey *fOther = - static_cast *>(&other); - return fLoc == fOther->fLoc; + inline bool operator == (const LocaleCacheKey &other) const { + return fLoc == other.fLoc; } - virtual CacheKeyBase *clone() const { + virtual CacheKeyBase *clone() const override { return new LocaleCacheKey(*this); } virtual const T *createObject( - const void *creationContext, UErrorCode &status) const; + const void *creationContext, UErrorCode &status) const override; /** * Use the locale id as the description. */ - virtual char *writeDescription(char *buffer, int32_t bufLen) const { + virtual char *writeDescription(char *buffer, int32_t bufLen) const override { const char *s = fLoc.getName(); uprv_strncpy(buffer, s, bufLen); buffer[bufLen - 1] = 0; @@ -293,8 +293,8 @@ class U_COMMON_API UnifiedCache : public UnifiedCacheBase { void flush() const; /** - * Configures at what point evcition of unused entries will begin. - * Eviction is triggered whenever the number of evictable keys exeeds + * Configures at what point eviction of unused entries will begin. + * Eviction is triggered whenever the number of evictable keys exceeds * BOTH count AND (number of in-use items) * (percentageOfInUseItems / 100). * Once the number of unused entries drops below one of these, * eviction ceases. Because eviction happens incrementally, @@ -315,7 +315,7 @@ class U_COMMON_API UnifiedCache : public UnifiedCacheBase { * settings. * * If a client already holds references to many different unique values - * in the cache such that the number of those unique values far exeeds + * in the cache such that the number of those unique values far exceeds * "count" then the cache may not be able to maintain this maximum. * However, if this happens, the cache still guarantees that the number of * unused entries will remain only a small percentage of the total cache @@ -341,7 +341,7 @@ class U_COMMON_API UnifiedCache : public UnifiedCacheBase { */ int32_t unusedCount() const; - virtual void handleUnreferencedObject() const; + virtual void handleUnreferencedObject() const override; virtual ~UnifiedCache(); private: @@ -465,7 +465,7 @@ class U_COMMON_API UnifiedCache : public UnifiedCacheBase { /** * Register a primary cache entry. A primary key is the first key to create * a given SharedObject value. Subsequent keys whose create function - * produce referneces to an already existing SharedObject are not primary - + * produce references to an already existing SharedObject are not primary - * they can be evicted and subsequently recreated. * * On entry, gCacheMutex must be held. -- cgit v1.2.3