Change the implementation of the character token and string methods to reduce initialization overhead
All methods operate on the same NSString instance instead of creating a new character token, e.g. when trimming or splitting the leading whitespace.
This commit is contained in:
1 parent
0911e46dba
commit
d8a55db4dc
5 files changed
+121
-80
No files matched your search
@@ -39,31 +39,44 @@
|
||||
return [_characters isHTMLWhitespaceString];
|
||||
}
|
||||
|
||||
- (HTMLCharacterToken *)tokenByRetainingLeadingWhitespace
|
||||
- (BOOL)isEmpty
|
||||
{
|
||||
return _characters.length == 0;
|
||||
}
|
||||
|
||||
- (void)retainLeadingWhitespace
|
||||
{
|
||||
NSUInteger index = _characters.leadingWhitespaceLength;
|
||||
if (index > 0) {
|
||||
[_characters setString:[_characters substringToIndex:index]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)trimLeadingWhitespace
|
||||
{
|
||||
NSUInteger index = _characters.leadingWhitespaceLength;
|
||||
if (index > 0) {
|
||||
[_characters setString:[_characters substringFromIndex:index]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)trimFormIndex:(NSUInteger)index
|
||||
{
|
||||
[_characters setString:[_characters substringFromIndex:index]];
|
||||
}
|
||||
|
||||
- (HTMLCharacterToken *)tokenBySplitingLeadingWhiteSpace
|
||||
{
|
||||
NSUInteger index = _characters.leadingWhitespaceLength;
|
||||
if (index > 0) {
|
||||
NSString *leading = [_characters substringToIndex:index];
|
||||
[_characters setString:[_characters substringFromIndex:index]];
|
||||
return [[HTMLCharacterToken alloc] initWithString:leading];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (HTMLCharacterToken *)tokenByTrimmingLeadingWhitespace
|
||||
{
|
||||
NSUInteger index = _characters.leadingWhitespaceLength;
|
||||
if (index < _characters.length) {
|
||||
NSString *remaining = [_characters substringFromIndex:index];
|
||||
return [[HTMLCharacterToken alloc] initWithString:remaining];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (HTMLCharacterToken *)tokenByTrimmingFormIndex:(NSUInteger)index
|
||||
{
|
||||
return [[HTMLCharacterToken alloc] initWithString:[_characters substringFromIndex:index]];
|
||||
}
|
||||
|
||||
#pragma mark - NSObject
|
||||
|
||||
- (BOOL)isEqual:(id)other
|
||||
|
||||
Reference in new issue
Block a user