26 static const int minNumberOfStringsForGarbageCollection = 300;
27 static const uint32 garbageCollectionInterval = 30000;
35 StartEndString (String::CharPointerType s, String::CharPointerType e) noexcept : start (s), end (e) {}
38 String::CharPointerType start, end;
41 static int compareStrings (
const String& s1,
const String& s2) noexcept {
return s1.
compare (s2); }
44 static int compareStrings (
const StartEndString& string1,
const String& string2) noexcept
46 String::CharPointerType s1 (string1.start), s2 (string2.
getCharPointer());
50 const int c1 = s1 < string1.end ? (int) s1.
getAndAdvance() : 0;
51 const int c2 = (int) s2.getAndAdvance();
52 const int diff = c1 - c2;
54 if (diff != 0)
return diff < 0 ? -1 : 1;
61 template <
typename NewStringType>
65 int end = strings.
size();
70 const int startComp = compareStrings (newString, startString);
75 const int halfway = (start + end) / 2;
86 const int halfwayComp = compareStrings (newString, halfwayString);
97 strings.
insert (start, newString);
103 if (newString ==
nullptr || *newString == 0)
107 garbageCollectIfNeeded();
113 if (start.isEmpty() || start == end)
117 garbageCollectIfNeeded();
118 return addPooledString (strings, StartEndString (start, end));
127 garbageCollectIfNeeded();
128 return addPooledString (strings, newString.
text);
137 garbageCollectIfNeeded();
138 return addPooledString (strings, newString);
141 void StringPool::garbageCollectIfNeeded()
143 if (strings.
size() > minNumberOfStringsForGarbageCollection
152 for (
int i = strings.
size(); --i >= 0;)
static StringPool & getGlobalPool() noexcept
CharPointerType getCharPointer() const noexcept
static uint32 getApproximateMillisecondCounter() noexcept
void insert(int indexToInsertAt, ParameterType newElement)
bool isEmpty() const noexcept
juce_wchar getAndAdvance() noexcept
int size() const noexcept
bool isEmpty() const noexcept
String::CharPointerType text
ElementType & getReference(int index) noexcept
int compare(const CharPointer other) const noexcept
String getPooledString(const String &original)
int compare(const String &other) const noexcept
void remove(int indexToRemove)