26static const int minNumberOfStringsForGarbageCollection = 300;
27static const uint32 garbageCollectionInterval = 30000;
40static int compareStrings (
const String& s1,
const String& s2)
noexcept {
return s1.compare (s2); }
41static int compareStrings (CharPointer_UTF8 s1,
const String& s2)
noexcept {
return s1.compare (s2.getCharPointer()); }
43static int compareStrings (
const StartEndString&
string1,
const String&
string2)
noexcept
49 const int c1 = s1 <
string1.end ? (
int) s1.getAndAdvance() : 0;
50 const int c2 = (
int) s2.getAndAdvance();
53 if (
diff != 0)
return diff < 0 ? -1 : 1;
60template <
typename NewStringType>
64 int end = strings.size();
68 const String&
startString = strings.getReference (start);
97 return strings.getReference (start);
106 garbageCollectIfNeeded();
116 garbageCollectIfNeeded();
126 garbageCollectIfNeeded();
127 return addPooledString (strings,
newString.text);
136 garbageCollectIfNeeded();
137 return addPooledString (strings,
newString);
140void StringPool::garbageCollectIfNeeded()
142 if (strings.size() > minNumberOfStringsForGarbageCollection
151 for (
int i = strings.size(); --i >= 0;)
152 if (strings.getReference (i).getReferenceCount() == 1)
Wraps a pointer to a null-terminated UTF-8 character string, and provides various methods to operate ...
bool isEmpty() const noexcept
Returns true if this pointer is pointing to a null character.
Automatically locks and unlocks a mutex object.
A StringPool holds a set of shared strings, which reduces storage overheads and improves comparison s...
String getPooledString(const String &original)
Returns a pointer to a shared copy of the string that is passed in.
StringPool() noexcept
Creates an empty pool.
static StringPool & getGlobalPool() noexcept
Returns a shared global pool which is used for things like Identifiers, XML parsing.
void garbageCollect()
Scans the pool, and removes any strings that are unreferenced.
A simple class for holding temporary references to a string literal or String.
CharPointer_UTF8 CharPointerType
This is the character encoding type used internally to store the string.
static uint32 getApproximateMillisecondCounter() noexcept
Less-accurate but faster version of getMillisecondCounter().
RangedDirectoryIterator end(const RangedDirectoryIterator &)
Returns a default-constructed sentinel value.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
unsigned int uint32
A platform-independent 32-bit unsigned integer type.