mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Optimisation to XML parsing of documents that contain large text sections.
This commit is contained in:
parent
faa7f256b7
commit
c5595695fe
3 changed files with 15 additions and 22 deletions
|
|
@ -89,14 +89,14 @@ char* MemoryOutputStream::prepareToWrite (size_t numBytes)
|
|||
if (storageNeeded >= blockToUse->getSize())
|
||||
blockToUse->ensureSize ((storageNeeded + jmin (storageNeeded / 2, (size_t) (1024 * 1024)) + 32) & ~31u);
|
||||
|
||||
data = static_cast <char*> (blockToUse->getData());
|
||||
data = static_cast<char*> (blockToUse->getData());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (storageNeeded > availableSize)
|
||||
return nullptr;
|
||||
|
||||
data = static_cast <char*> (externalData);
|
||||
data = static_cast<char*> (externalData);
|
||||
}
|
||||
|
||||
char* const writePointer = data + position;
|
||||
|
|
@ -157,7 +157,7 @@ const void* MemoryOutputStream::getData() const noexcept
|
|||
return externalData;
|
||||
|
||||
if (blockToUse->getSize() > size)
|
||||
static_cast <char*> (blockToUse->getData()) [size] = 0;
|
||||
static_cast<char*> (blockToUse->getData()) [size] = 0;
|
||||
|
||||
return blockToUse->getData();
|
||||
}
|
||||
|
|
@ -194,7 +194,7 @@ int64 MemoryOutputStream::writeFromInputStream (InputStream& source, int64 maxNu
|
|||
|
||||
String MemoryOutputStream::toUTF8() const
|
||||
{
|
||||
const char* const d = static_cast <const char*> (getData());
|
||||
const char* const d = static_cast<const char*> (getData());
|
||||
return String (CharPointer_UTF8 (d), CharPointer_UTF8 (d + getDataSize()));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -458,9 +458,9 @@ public:
|
|||
}
|
||||
|
||||
/** Returns true if the first character of this string is whitespace. */
|
||||
bool isWhitespace() const noexcept { return *data == ' ' || (*data <= 13 && *data >= 9); }
|
||||
bool isWhitespace() const noexcept { const CharType c = *data; return c == ' ' || (c <= 13 && c >= 9); }
|
||||
/** Returns true if the first character of this string is a digit. */
|
||||
bool isDigit() const noexcept { return *data >= '0' && *data <= '9'; }
|
||||
bool isDigit() const noexcept { const CharType c = *data; return c >= '0' && c <= '9'; }
|
||||
/** Returns true if the first character of this string is a letter. */
|
||||
bool isLetter() const noexcept { return CharacterFunctions::isLetter (operator*()) != 0; }
|
||||
/** Returns true if the first character of this string is a letter or digit. */
|
||||
|
|
|
|||
|
|
@ -555,7 +555,8 @@ void XmlDocument::readChildElements (XmlElement& parent)
|
|||
else // must be a character block
|
||||
{
|
||||
input = preWhitespaceInput; // roll back to include the leading whitespace
|
||||
String textElementContent;
|
||||
MemoryOutputStream textElementContent;
|
||||
bool contentShouldBeUsed = ! ignoreEmptyTextElements;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
|
|
@ -602,28 +603,20 @@ void XmlDocument::readChildElements (XmlElement& parent)
|
|||
input = entity.getCharPointer();
|
||||
outOfData = false;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
XmlElement* const n = readNextElement (true);
|
||||
|
||||
if (n == nullptr)
|
||||
break;
|
||||
|
||||
while (XmlElement* n = readNextElement (true))
|
||||
childAppender.append (n);
|
||||
}
|
||||
|
||||
input = oldInput;
|
||||
outOfData = oldOutOfData;
|
||||
}
|
||||
else
|
||||
{
|
||||
textElementContent += entity;
|
||||
textElementContent << entity;
|
||||
contentShouldBeUsed = contentShouldBeUsed || entity.containsNonWhitespaceChars();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const String::CharPointerType start (input);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
const juce_wchar nextChar = *input;
|
||||
|
|
@ -638,15 +631,15 @@ void XmlDocument::readChildElements (XmlElement& parent)
|
|||
return;
|
||||
}
|
||||
|
||||
textElementContent.appendUTF8Char (nextChar);
|
||||
contentShouldBeUsed = contentShouldBeUsed || ! CharacterFunctions::isWhitespace (nextChar);
|
||||
++input;
|
||||
}
|
||||
|
||||
textElementContent.appendCharPointer (start, input);
|
||||
}
|
||||
}
|
||||
|
||||
if ((! ignoreEmptyTextElements) || textElementContent.containsNonWhitespaceChars())
|
||||
childAppender.append (XmlElement::createTextElement (textElementContent));
|
||||
if (contentShouldBeUsed)
|
||||
childAppender.append (XmlElement::createTextElement (textElementContent.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue