summaryrefslogtreecommitdiffstats
path: root/contrib/libs/icu/common/unifiedcache.h
diff options
context:
space:
mode:
authorromankoshelev <[email protected]>2023-08-09 20:07:20 +0300
committerromankoshelev <[email protected]>2023-08-09 20:59:13 +0300
commitfd82fb12fb45e71a02c628e45b12c50c0dd0d308 (patch)
treef582b79f9002ab1d083e9acda600dfb3551c47b6 /contrib/libs/icu/common/unifiedcache.h
parentbf862ddf5c6178e1bb5e4fb3f7c61015deebe284 (diff)
Update ICU to 70.1
Diffstat (limited to 'contrib/libs/icu/common/unifiedcache.h')
-rw-r--r--contrib/libs/icu/common/unifiedcache.h96
1 files changed, 48 insertions, 48 deletions
diff --git a/contrib/libs/icu/common/unifiedcache.h b/contrib/libs/icu/common/unifiedcache.h
index d6c9945126c..07a734b8bd5 100644
--- a/contrib/libs/icu/common/unifiedcache.h
+++ b/contrib/libs/icu/common/unifiedcache.h
@@ -34,13 +34,13 @@ class UnifiedCache;
*/
class U_COMMON_API CacheKeyBase : public UObject {
public:
- CacheKeyBase() : fCreationStatus(U_ZERO_ERROR), fIsMaster(FALSE) {}
+ CacheKeyBase() : fCreationStatus(U_ZERO_ERROR), fIsPrimary(false) {}
/**
* Copy constructor. Needed to support cloning.
*/
CacheKeyBase(const CacheKeyBase &other)
- : UObject(other), fCreationStatus(other.fCreationStatus), fIsMaster(FALSE) { }
+ : UObject(other), fCreationStatus(other.fCreationStatus), fIsPrimary(false) { }
virtual ~CacheKeyBase();
/**
@@ -54,11 +54,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
* that getting an object from the cache and returning it without calling
@@ -80,15 +75,22 @@ 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 fIsMaster;
+ mutable UBool fIsPrimary;
friend class UnifiedCache;
};
@@ -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<int32_t>(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<typename T>
class LocaleCacheKey : public CacheKey<T> {
protected:
Locale fLoc;
+ virtual bool equals(const CacheKeyBase &other) const override {
+ if (!CacheKey<T>::equals(other)) {
+ return false;
+ }
+ // We know this and other are of same class because equals() on
+ // CacheKey returned true.
+ return operator==(static_cast<const LocaleCacheKey<T> &>(other));
+ }
public:
LocaleCacheKey(const Locale &loc) : fLoc(loc) {}
LocaleCacheKey(const LocaleCacheKey<T> &other)
: CacheKey<T>(other), fLoc(other.fLoc) { }
virtual ~LocaleCacheKey() { }
- virtual int32_t hashCode() const {
+ virtual int32_t hashCode() const override {
return (int32_t)(37u * (uint32_t)CacheKey<T>::hashCode() + (uint32_t)fLoc.hashCode());
}
- virtual UBool operator == (const CacheKeyBase &other) const {
- // reflexive
- if (this == &other) {
- return TRUE;
- }
- if (!CacheKey<T>::operator == (other)) {
- return FALSE;
- }
- // We know this and other are of same class because operator== on
- // CacheKey returned true.
- const LocaleCacheKey<T> *fOther =
- static_cast<const LocaleCacheKey<T> *>(&other);
- return fLoc == fOther->fLoc;
+ inline bool operator == (const LocaleCacheKey<T> &other) const {
+ return fLoc == other.fLoc;
}
- virtual CacheKeyBase *clone() const {
+ virtual CacheKeyBase *clone() const override {
return new LocaleCacheKey<T>(*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:
@@ -359,7 +359,7 @@ class U_COMMON_API UnifiedCache : public UnifiedCacheBase {
/**
* Flushes the contents of the cache. If cache values hold references to other
- * cache values then _flush should be called in a loop until it returns FALSE.
+ * cache values then _flush should be called in a loop until it returns false.
*
* On entry, gCacheMutex must be held.
* On exit, those values with are evictable are flushed.
@@ -370,7 +370,7 @@ class U_COMMON_API UnifiedCache : public UnifiedCacheBase {
* hard (external) references are not deleted, but are detached from
* the cache, so that a subsequent removeRefs can delete them.
* _flush is not thread safe when all is true.
- * @return TRUE if any value in cache was flushed or FALSE otherwise.
+ * @return true if any value in cache was flushed or false otherwise.
*/
UBool _flush(UBool all) const;
@@ -395,11 +395,11 @@ class U_COMMON_API UnifiedCache : public UnifiedCacheBase {
* Attempts to fetch value and status for key from cache.
* On entry, gCacheMutex must not be held value must be NULL and status must
* be U_ZERO_ERROR.
- * On exit, either returns FALSE (In this
- * case caller should try to create the object) or returns TRUE with value
+ * On exit, either returns false (In this
+ * case caller should try to create the object) or returns true with value
* pointing to the fetched value and status set to fetched status. When
- * FALSE is returned status may be set to failure if an in progress hash
- * entry could not be made but value will remain unchanged. When TRUE is
+ * false is returned status may be set to failure if an in progress hash
+ * entry could not be made but value will remain unchanged. When true is
* returned, caller must call removeRef() on value.
*/
UBool _poll(
@@ -463,17 +463,17 @@ class U_COMMON_API UnifiedCache : public UnifiedCacheBase {
void _runEvictionSlice() const;
/**
- * Register a master cache entry. A master key is the first key to create
+ * 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 masters -
+ * produce references to an already existing SharedObject are not primary -
* they can be evicted and subsequently recreated.
*
* On entry, gCacheMutex must be held.
- * On exit, items in use count incremented, entry is marked as a master
+ * On exit, items in use count incremented, entry is marked as a primary
* entry, and value registered with cache so that subsequent calls to
* addRef() and removeRef() on it correctly interact with the cache.
*/
- void _registerMaster(const CacheKeyBase *theKey, const SharedObject *value) const;
+ void _registerPrimary(const CacheKeyBase *theKey, const SharedObject *value) const;
/**
* Store a value and creation error status in given hash entry.