Browse Source

Removed the (broken) String::Concatenator class - this awful class should never have existed. Instead, for fast string concatenation, write to a MemoryOutputStream and get the result with MemoryOutputStream::toString().

tags/2021-05-28
jules 14 years ago
parent
commit
14c6561dda
4 changed files with 17 additions and 84 deletions
  1. +1
    -1
      modules/juce_core/text/juce_CharPointer_UTF8.h
  2. +0
    -25
      modules/juce_core/text/juce_String.cpp
  3. +0
    -25
      modules/juce_core/text/juce_String.h
  4. +16
    -33
      modules/juce_core/xml/juce_XmlElement.cpp

+ 1
- 1
modules/juce_core/text/juce_CharPointer_UTF8.h View File

@@ -100,7 +100,7 @@ public:
for (size_t i = 1; i <= numExtraValues; ++i)
{
const juce_wchar nextByte = (juce_wchar) (uint8) data [i];
const uint8 nextByte = (uint8) data [i];
if ((nextByte & 0xc0) != 0x80)
break;


+ 0
- 25
modules/juce_core/text/juce_String.cpp View File

@@ -2062,31 +2062,6 @@ String String::fromUTF8 (const char* const buffer, int bufferSizeBytes)
#pragma warning (pop)
#endif
//==============================================================================
String::Concatenator::Concatenator (String& stringToAppendTo)
: result (stringToAppendTo),
nextIndex (stringToAppendTo.length())
{
}
String::Concatenator::~Concatenator()
{
}
void String::Concatenator::append (const String& s)
{
const int len = s.length();
if (len > 0)
{
size_t extraBytes = s.getCharPointer().sizeInBytes();
result.preallocateBytes (nextIndex + extraBytes);
CharPointerType (result.text + nextIndex).writeAll (s.text);
nextIndex += len;
}
}
//==============================================================================
//==============================================================================
#if JUCE_UNIT_TESTS


+ 0
- 25
modules/juce_core/text/juce_String.h View File

@@ -1172,32 +1172,7 @@ public:
void swapWith (String& other) noexcept;
//==============================================================================
/** A helper class to improve performance when concatenating many large strings
together.
Because appending one string to another involves measuring the length of
both strings, repeatedly doing this for many long strings will become
an exponentially slow operation. This class uses some internal state to
avoid that, so that each append operation only needs to measure the length
of the appended string.
*/
class JUCE_API Concatenator
{
public:
Concatenator (String& stringToAppendTo);
~Concatenator();
void append (const String& s);
private:
String& result;
int nextIndex;
JUCE_DECLARE_NON_COPYABLE (Concatenator);
};
#if JUCE_MAC || JUCE_IOS || DOXYGEN
//==============================================================================
/** MAC ONLY - Creates a String from an OSX CFString. */
static String fromCFString (CFStringRef cfString);


+ 16
- 33
modules/juce_core/xml/juce_XmlElement.cpp View File

@@ -127,7 +127,8 @@ XmlElement::~XmlElement() noexcept
//==============================================================================
namespace XmlOutputFunctions
{
/*bool isLegalXmlCharSlow (const juce_wchar character) noexcept
#if 0 // (These functions are just used to generate the lookup table used below)
bool isLegalXmlCharSlow (const juce_wchar character) noexcept
{
if ((character >= 'a' && character <= 'z')
|| (character >= 'A' && character <= 'Z')
@@ -146,7 +147,7 @@ namespace XmlOutputFunctions
return false;
}
void generateLegalCharConstants()
void generateLegalCharLookupTable()
{
uint8 n[32] = { 0 };
for (int i = 0; i < 256; ++i)
@@ -158,7 +159,8 @@ namespace XmlOutputFunctions
s << (int) n[i] << ", ";
DBG (s);
}*/
}
#endif
bool isLegalXmlChar (const uint32 c) noexcept
{
@@ -253,10 +255,10 @@ void XmlElement::writeElementAsText (OutputStream& outputStream,
{
outputStream.writeByte ('>');
XmlElement* child = firstChildElement;
bool lastWasTextNode = false;
while (child != nullptr)
for (XmlElement* child = firstChildElement; child != nullptr; child = child->nextListItem)
{
if (child->isTextElement())
{
@@ -272,8 +274,6 @@ void XmlElement::writeElementAsText (OutputStream& outputStream,
lastWasTextNode ? 0 : (indentationLevel + (indentationLevel >= 0 ? 2 : 0)), lineWrapLength);
lastWasTextNode = false;
}
child = child->getNextElement();
}
if (indentationLevel >= 0 && ! lastWasTextNode)
@@ -568,17 +568,11 @@ XmlElement* XmlElement::getChildElement (const int index) const noexcept
XmlElement* XmlElement::getChildByName (const String& childName) const noexcept
{
XmlElement* child = firstChildElement;
while (child != nullptr)
{
for (XmlElement* child = firstChildElement; child != nullptr; child = child->nextListItem)
if (child->hasTagName (childName))
break;
child = child->nextListItem;
}
return child;
return child;
return nullptr;
}
void XmlElement::addChildElement (XmlElement* const newNode) noexcept
@@ -646,14 +640,12 @@ bool XmlElement::isEquivalentTo (const XmlElement* const other,
if (ignoreOrderOfAttributes)
{
int totalAtts = 0;
const XmlAttributeNode* att = attributes;
while (att != nullptr)
for (const XmlAttributeNode* att = attributes; att != nullptr; att = att->nextListItem)
{
if (! other->compareAttribute (att->name, att->value))
return false;
att = att->nextListItem;
++totalAtts;
}
@@ -740,9 +732,7 @@ XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLo
if (this == elementToLookFor || elementToLookFor == nullptr)
return nullptr;
XmlElement* child = firstChildElement;
while (child != nullptr)
for (XmlElement* child = firstChildElement; child != nullptr; child = child->nextListItem)
{
if (elementToLookFor == child)
return this;
@@ -751,8 +741,6 @@ XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLo
if (found != nullptr)
return found;
child = child->nextListItem;
}
return nullptr;
@@ -806,17 +794,12 @@ String XmlElement::getAllSubText() const
if (isTextElement())
return getText();
String result;
String::Concatenator concatenator (result);
const XmlElement* child = firstChildElement;
MemoryOutputStream mem (1024);
while (child != nullptr)
{
concatenator.append (child->getAllSubText());
child = child->nextListItem;
}
for (const XmlElement* child = firstChildElement; child != nullptr; child = child->nextListItem)
mem << child->getAllSubText();
return result;
return mem.toString();
}
String XmlElement::getChildElementAllSubText (const String& childTagName,


Loading…
Cancel
Save