More perf increases

This commit is contained in:
Curtis Hard
2019-12-24 09:27:06 +00:00
parent df5b3219ca
commit c6e59a9280
4 changed files with 19 additions and 11 deletions
@@ -124,7 +124,8 @@
requiredParameters = [self.class requiredParameterCount];
NSInteger sets = 0;
IJSVGPathDataSequence* sequence = [self.class pathDataSequence];
parameters = IJSVGParsePathDataStreamSequence(str, dataStream, sequence, requiredParameters, &sets);
parameters = IJSVGParsePathDataStreamSequence(str.UTF8String, str.length,
dataStream, sequence, requiredParameters, &sets);
if (sets <= 1) {
CGFloat* subParams = [self parametersFromIndexOffset:0];
@@ -33,7 +33,8 @@ IJSVGPathDataStream* IJSVGPathDataStreamCreate(NSUInteger floatCount, NSUInteger
void IJSVGPathDataStreamRelease(IJSVGPathDataStream* buffer);
IJSVGPathDataSequence* IJSVGPathDataSequenceCreateWithType(IJSVGPathDataSequence type, NSInteger length);
CGFloat* _Nullable IJSVGParsePathDataStreamSequence(NSString* string, IJSVGPathDataStream* dataStream, IJSVGPathDataSequence* _Nullable sequence,
CGFloat* _Nullable IJSVGParsePathDataStreamSequence(const char* commandChars, NSInteger commandCharLength,
IJSVGPathDataStream* dataStream, IJSVGPathDataSequence* _Nullable sequence,
NSInteger commandLength, NSInteger* _Nullable commandsFound);
@end
@@ -51,8 +51,9 @@ void IJSVGPathDataStreamRelease(IJSVGPathDataStream* buffer)
free(buffer);
};
CGFloat* _Nullable IJSVGParsePathDataStreamSequence(NSString* string, IJSVGPathDataStream* dataStream,
IJSVGPathDataSequence* _Nullable sequence, NSInteger commandLength, NSInteger* _Nullable commandsFound)
CGFloat* _Nullable IJSVGParsePathDataStreamSequence(const char* commandChars, NSInteger commandCharLength,
IJSVGPathDataStream* dataStream, IJSVGPathDataSequence* _Nullable sequence,
NSInteger commandLength, NSInteger* _Nullable commandsFound)
{
// if no command length, its completely pointless function,
// so just return null and set commandsFound to 0, if we dont
@@ -71,12 +72,12 @@ CGFloat* _Nullable IJSVGParsePathDataStreamSequence(NSString* string, IJSVGPathD
NSInteger i = 0;
NSInteger counter = 0;
const char* cString = string.UTF8String;
const char* cString = commandChars;
const char* validChars = "eE+-.";
// this is much faster then doing strlen as it doesnt need
// to compute the length
NSInteger sLength = string.length;
NSInteger sLength = commandCharLength;
NSInteger sLengthMinusOne = sLength - 1;
bool isDecimal = false;
@@ -151,17 +152,20 @@ CGFloat* _Nullable IJSVGParsePathDataStreamSequence(NSString* string, IJSVGPathD
sizeof(CGFloat) * dataStream->floatCount);
}
// add the float
// add the float - for performance reasons, we can simply set the
// null value of the end of the string instead of nulling out
// with memset \0 - huzzah!
dataStream->charBuffer[bufferCount] = '\0';
dataStream->floatBuffer[counter++] = IJSVGParseFloat(dataStream->charBuffer);
// memory clean and counter resets
memset(dataStream->charBuffer, '\0', sizeof(char) * bufferCount);
// reset
isDecimal = false;
bufferCount = 0;
}
i++;
}
// set commands found - only if there is one
if (commandsFound != NULL) {
*commandsFound = (NSInteger)round(counter / commandLength);
}
@@ -436,7 +436,8 @@ CGFloat degrees_to_radians(CGFloat degrees)
size:(NSInteger*)length
{
IJSVGPathDataStream* stream = IJSVGPathDataStreamCreateDefault();
CGFloat* floats = IJSVGParsePathDataStreamSequence(string, stream, NULL, 1, length);
CGFloat* floats = IJSVGParsePathDataStreamSequence(string.UTF8String, string.length,
stream, NULL, 1, length);
IJSVGPathDataStreamRelease(stream);
return floats;
}
@@ -445,7 +446,8 @@ CGFloat degrees_to_radians(CGFloat degrees)
{
IJSVGPathDataStream* stream = IJSVGPathDataStreamCreate(4,
IJSVG_DATA_STREAM_DEFAULT_BUFFER_COUNT_CHAR);
CGFloat* floats = IJSVGParsePathDataStreamSequence(string, stream, NULL, 1, NULL);
CGFloat* floats = IJSVGParsePathDataStreamSequence(string.UTF8String,
string.length, stream, NULL, 1, NULL);
IJSVGPathDataStreamRelease(stream);
return floats;
}