| 12373 | { |
| 12374 | template <class StringType> |
| 12375 | String::CharPointerType getPooledStringFromArray (Array<String>& strings, |
| 12376 | StringType newString, |
| 12377 | const CriticalSection& lock) |
| 12378 | { |
| 12379 | const ScopedLock sl (lock); |
| 12380 | int start = 0; |
| 12381 | int end = strings.size(); |
| 12382 | |
| 12383 | for (;;) |
| 12384 | { |
| 12385 | if (start >= end) |
| 12386 | { |
| 12387 | jassert (start <= end); |
| 12388 | strings.insert (start, newString); |
| 12389 | return strings.getReference (start).getCharPointer(); |
| 12390 | } |
| 12391 | else |
| 12392 | { |
| 12393 | const String& startString = strings.getReference (start); |
| 12394 | |
| 12395 | if (startString == newString) |
| 12396 | return startString.getCharPointer(); |
| 12397 | |
| 12398 | const int halfway = (start + end) >> 1; |
| 12399 | |
| 12400 | if (halfway == start) |
| 12401 | { |
| 12402 | if (startString.compare (newString) < 0) |
| 12403 | ++start; |
| 12404 | |
| 12405 | strings.insert (start, newString); |
| 12406 | return strings.getReference (start).getCharPointer(); |
| 12407 | } |
| 12408 | |
| 12409 | const int comp = strings.getReference (halfway).compare (newString); |
| 12410 | |
| 12411 | if (comp == 0) |
| 12412 | return strings.getReference (halfway).getCharPointer(); |
| 12413 | else if (comp < 0) |
| 12414 | start = halfway; |
| 12415 | else |
| 12416 | end = halfway; |
| 12417 | } |
| 12418 | } |
| 12419 | } |
| 12420 | } |
| 12421 | |
| 12422 | String::CharPointerType StringPool::getPooledString (const String& s) |
no test coverage detected