From 5ae735344330513988489b2bdc7d794238cc1a57 Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 2 Sep 2013 14:08:39 +0100 Subject: [PATCH] Minor clean-ups + optimisations. --- modules/juce_core/maths/juce_BigInteger.cpp | 6 +++--- modules/juce_core/memory/juce_MemoryBlock.cpp | 10 +++++----- modules/juce_core/memory/juce_MemoryBlock.h | 19 ++++++------------- modules/juce_core/xml/juce_XmlElement.cpp | 5 +---- .../drawables/juce_SVGParser.cpp | 2 +- .../juce_RelativeParallelogram.cpp | 2 +- .../positioning/juce_RelativeParallelogram.h | 2 +- 7 files changed, 18 insertions(+), 28 deletions(-) diff --git a/modules/juce_core/maths/juce_BigInteger.cpp b/modules/juce_core/maths/juce_BigInteger.cpp index 398fbc354b..0cfc5646b7 100644 --- a/modules/juce_core/maths/juce_BigInteger.cpp +++ b/modules/juce_core/maths/juce_BigInteger.cpp @@ -956,7 +956,9 @@ String BigInteger::toString (const int base, const int minimumNumCharacters) con void BigInteger::parseString (const String& text, const int base) { clear(); - String::CharPointerType t (text.getCharPointer()); + String::CharPointerType t (text.getCharPointer().findEndOfWhitespace()); + + setNegative (*t == (juce_wchar) '-'); if (base == 2 || base == 8 || base == 16) { @@ -997,8 +999,6 @@ void BigInteger::parseString (const String& text, const int base) } } } - - setNegative (text.trimStart().startsWithChar ('-')); } MemoryBlock BigInteger::toMemoryBlock() const diff --git a/modules/juce_core/memory/juce_MemoryBlock.cpp b/modules/juce_core/memory/juce_MemoryBlock.cpp index 2daa1dbfa7..16438f6def 100644 --- a/modules/juce_core/memory/juce_MemoryBlock.cpp +++ b/modules/juce_core/memory/juce_MemoryBlock.cpp @@ -88,14 +88,14 @@ MemoryBlock& MemoryBlock::operator= (const MemoryBlock& other) #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS MemoryBlock::MemoryBlock (MemoryBlock&& other) noexcept - : data (static_cast &&> (other.data)), + : data (static_cast &&> (other.data)), size (other.size) { } MemoryBlock& MemoryBlock::operator= (MemoryBlock&& other) noexcept { - data = static_cast &&> (other.data); + data = static_cast &&> (other.data); size = other.size; return *this; } @@ -352,7 +352,7 @@ void MemoryBlock::loadFromHexString (const String& hex) } //============================================================================== -const char* const MemoryBlock::encodingTable = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+"; +static const char* const base64EncodingTable = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+"; String MemoryBlock::toBase64Encoding() const { @@ -367,7 +367,7 @@ String MemoryBlock::toBase64Encoding() const d.write ('.'); for (size_t i = 0; i < numChars; ++i) - d.write ((juce_wchar) (uint8) encodingTable [getBitRange (i * 6, 6)]); + d.write ((juce_wchar) (uint8) base64EncodingTable [getBitRange (i * 6, 6)]); d.writeNull(); return destString; @@ -396,7 +396,7 @@ bool MemoryBlock::fromBase64Encoding (const String& s) for (int j = 0; j < 64; ++j) { - if (encodingTable[j] == c) + if (base64EncodingTable[j] == c) { setBitRange ((size_t) pos, 6, j); pos += 6; diff --git a/modules/juce_core/memory/juce_MemoryBlock.h b/modules/juce_core/memory/juce_MemoryBlock.h index 650218b9bf..62eeec9fdd 100644 --- a/modules/juce_core/memory/juce_MemoryBlock.h +++ b/modules/juce_core/memory/juce_MemoryBlock.h @@ -51,7 +51,7 @@ public: bool initialiseToZero = false); /** Creates a copy of another memory block. */ - MemoryBlock (const MemoryBlock& other); + MemoryBlock (const MemoryBlock&); /** Creates a memory block using a copy of a block of data. @@ -64,31 +64,27 @@ public: ~MemoryBlock() noexcept; /** Copies another memory block onto this one. - This block will be resized and copied to exactly match the other one. */ - MemoryBlock& operator= (const MemoryBlock& other); + MemoryBlock& operator= (const MemoryBlock&); #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS - MemoryBlock (MemoryBlock&& other) noexcept; - MemoryBlock& operator= (MemoryBlock&& other) noexcept; + MemoryBlock (MemoryBlock&&) noexcept; + MemoryBlock& operator= (MemoryBlock&&) noexcept; #endif //============================================================================== /** Compares two memory blocks. - @returns true only if the two blocks are the same size and have identical contents. */ bool operator== (const MemoryBlock& other) const noexcept; /** Compares two memory blocks. - @returns true if the two blocks are different sizes or have different contents. */ bool operator!= (const MemoryBlock& other) const noexcept; - /** Returns true if the data in this MemoryBlock matches the raw bytes passed-in. - */ + /** Returns true if the data in this MemoryBlock matches the raw bytes passed-in. */ bool matches (const void* data, size_t dataSize) const noexcept; //============================================================================== @@ -100,7 +96,6 @@ public: void* getData() const noexcept { return data; } /** Returns a byte from the memory block. - This returns a reference, so you can also use it to set a byte. */ template @@ -140,7 +135,6 @@ public: //============================================================================== /** Fills the entire memory block with a repeated byte value. - This is handy for clearing a block of memory to zero. */ void fillWith (uint8 valueToUse) noexcept; @@ -246,9 +240,8 @@ public: private: //============================================================================== - HeapBlock data; + HeapBlock data; size_t size; - static const char* const encodingTable; JUCE_LEAK_DETECTOR (MemoryBlock) }; diff --git a/modules/juce_core/xml/juce_XmlElement.cpp b/modules/juce_core/xml/juce_XmlElement.cpp index 45ad447cfa..6f10b022ec 100644 --- a/modules/juce_core/xml/juce_XmlElement.cpp +++ b/modules/juce_core/xml/juce_XmlElement.cpp @@ -470,10 +470,7 @@ bool XmlElement::getBoolAttribute (const String& attributeName, const bool defau { if (att->hasName (attributeName)) { - juce_wchar firstChar = att->value[0]; - - if (CharacterFunctions::isWhitespace (firstChar)) - firstChar = att->value.trimStart() [0]; + const juce_wchar firstChar = *(att->value.getCharPointer().findEndOfWhitespace()); return firstChar == '1' || firstChar == 't' diff --git a/modules/juce_gui_basics/drawables/juce_SVGParser.cpp b/modules/juce_gui_basics/drawables/juce_SVGParser.cpp index 1fe3205dfe..1272dcff93 100644 --- a/modules/juce_gui_basics/drawables/juce_SVGParser.cpp +++ b/modules/juce_gui_basics/drawables/juce_SVGParser.cpp @@ -1101,7 +1101,7 @@ private: return Colours::findColourForName (s, defaultColour); } - static const AffineTransform parseTransform (String t) + static AffineTransform parseTransform (String t) { AffineTransform result; diff --git a/modules/juce_gui_basics/positioning/juce_RelativeParallelogram.cpp b/modules/juce_gui_basics/positioning/juce_RelativeParallelogram.cpp index 0be3594e0d..77e3a7597d 100644 --- a/modules/juce_gui_basics/positioning/juce_RelativeParallelogram.cpp +++ b/modules/juce_gui_basics/positioning/juce_RelativeParallelogram.cpp @@ -77,7 +77,7 @@ void RelativeParallelogram::getPath (Path& path, Expression::Scope* const scope) path.closeSubPath(); } -const AffineTransform RelativeParallelogram::resetToPerpendicular (Expression::Scope* const scope) +AffineTransform RelativeParallelogram::resetToPerpendicular (Expression::Scope* const scope) { Point corners[3]; resolveThreePoints (corners, scope); diff --git a/modules/juce_gui_basics/positioning/juce_RelativeParallelogram.h b/modules/juce_gui_basics/positioning/juce_RelativeParallelogram.h index 3e78b4aeb4..00a3555b24 100644 --- a/modules/juce_gui_basics/positioning/juce_RelativeParallelogram.h +++ b/modules/juce_gui_basics/positioning/juce_RelativeParallelogram.h @@ -47,7 +47,7 @@ public: void resolveFourCorners (Point* points, Expression::Scope* scope) const; const Rectangle getBounds (Expression::Scope* scope) const; void getPath (Path& path, Expression::Scope* scope) const; - const AffineTransform resetToPerpendicular (Expression::Scope* scope); + AffineTransform resetToPerpendicular (Expression::Scope* scope); bool isDynamic() const; bool operator== (const RelativeParallelogram& other) const noexcept;