From d7825c23fe7cb1256cdb676ad4a6792ac4c0348a Mon Sep 17 00:00:00 2001 From: jules Date: Sun, 2 Sep 2012 21:35:08 +0100 Subject: [PATCH] Minor optimisations to StringArray. --- modules/juce_core/text/juce_StringArray.cpp | 35 +++++++-------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/modules/juce_core/text/juce_StringArray.cpp b/modules/juce_core/text/juce_StringArray.cpp index d275fee02b..47de97dbd8 100644 --- a/modules/juce_core/text/juce_StringArray.cpp +++ b/modules/juce_core/text/juce_StringArray.cpp @@ -371,7 +371,7 @@ int StringArray::addTokens (const String& text, const String& breakCharacters, c String::CharPointerType tokenEnd (CharacterFunctions::findEndOfToken (t, breakCharacters.getCharPointer(), quoteCharacters.getCharPointer())); - add (String (t, tokenEnd)); + strings.add (String (t, tokenEnd)); ++num; if (tokenEnd.isEmpty()) @@ -392,35 +392,22 @@ int StringArray::addLines (const String& sourceText) while (! finished) { - String::CharPointerType startOfLine (text); - size_t numChars = 0; - - for (;;) + for (String::CharPointerType startOfLine (text);;) { - const juce_wchar c = text.getAndAdvance(); + const String::CharPointerType endOfLine (text); - if (c == 0) + switch (text.getAndAdvance()) { - finished = true; - break; + case 0: finished = true; break; + case '\n': break; + case '\r': if (*text == '\n') ++text; break; + default: continue; } - if (c == '\n') - break; - - if (c == '\r') - { - if (*text == '\n') - ++text; - - break; - } - - ++numChars; + strings.add (String (startOfLine, endOfLine)); + ++numLines; + break; } - - add (String (startOfLine, numChars)); - ++numLines; } return numLines;