Index: src/OFXMLParser.h ================================================================== --- src/OFXMLParser.h +++ src/OFXMLParser.h @@ -146,11 +146,11 @@ OF_XMLPARSER_IN_COMMENT_1, OF_XMLPARSER_IN_COMMENT_2, OF_XMLPARSER_IN_DOCTYPE, OF_XMLPARSER_NUM_STATES } _state; - OFDataArray *_cache; + OFDataArray *_buffer; OFString *_name, *_prefix; OFMutableArray *_namespaces, *_attributes; OFString *_attributeName, *_attributePrefix; char _delimiter; OFMutableArray *_previous; Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -40,44 +40,44 @@ typedef void (*state_function)(id, SEL, const char*, size_t*, size_t*); static SEL selectors[OF_XMLPARSER_NUM_STATES]; static state_function lookupTable[OF_XMLPARSER_NUM_STATES]; static OF_INLINE void -cache_append(OFDataArray *cache, const char *string, +buffer_append(OFDataArray *buffer, const char *string, of_string_encoding_t encoding, size_t length) { if (OF_LIKELY(encoding == OF_STRING_ENCODING_UTF_8)) - [cache addItems: string - count: length]; + [buffer addItems: string + count: length]; else { void *pool = objc_autoreleasePoolPush(); OFString *tmp = [OFString stringWithCString: string encoding: encoding length: length]; - [cache addItems: [tmp UTF8String] - count: [tmp UTF8StringLength]]; + [buffer addItems: [tmp UTF8String] + count: [tmp UTF8StringLength]]; objc_autoreleasePoolPop(pool); } } static OFString* -transform_string(OFDataArray *cache, size_t cut, BOOL unescape, +transform_string(OFDataArray *buffer, size_t cut, BOOL unescape, id delegate) { char *items; size_t i, length; BOOL hasEntities = NO; OFString *ret; - items = [cache items]; - length = [cache count] - cut; + items = [buffer items]; + length = [buffer count] - cut; for (i = 0; i < length; i++) { if (items[i] == '\r') { if (i + 1 < length && items[i + 1] == '\n') { - [cache removeItemAtIndex: i]; - items = [cache items]; + [buffer removeItemAtIndex: i]; + items = [buffer items]; i--; length--; } else items[i] = '\n'; @@ -183,11 +183,11 @@ @try { void *pool; OFMutableDictionary *dict; - _cache = [[OFBigDataArray alloc] init]; + _buffer = [[OFBigDataArray alloc] init]; _previous = [[OFMutableArray alloc] init]; _namespaces = [[OFMutableArray alloc] init]; _attributes = [[OFMutableArray alloc] init]; pool = objc_autoreleasePoolPush(); @@ -210,11 +210,11 @@ return self; } - (void)dealloc { - [_cache release]; + [_buffer release]; [_name release]; [_prefix release]; [_namespaces release]; [_attributes release]; [_attributeName release]; @@ -265,11 +265,11 @@ _lastCarriageReturn = (buffer[i] == '\r'); } /* In OF_XMLPARSER_IN_TAG, there can be only spaces */ if (length - last > 0 && _state != OF_XMLPARSER_IN_TAG) - cache_append(_cache, buffer + last, _encoding, length - last); + buffer_append(_buffer, buffer + last, _encoding, length - last); } - (void)parseString: (OFString*)string { [self parseBuffer: [string UTF8String] @@ -327,25 +327,25 @@ if (buffer[*i] != '<') return; if ((length = *i - *last) > 0) - cache_append(_cache, buffer + *last, _encoding, length); + buffer_append(_buffer, buffer + *last, _encoding, length); - if ([_cache count] > 0) { + if ([_buffer count] > 0) { void *pool = objc_autoreleasePoolPush(); - OFString *characters = transform_string(_cache, 0, YES, self); + OFString *characters = transform_string(_buffer, 0, YES, self); if ([_delegate respondsToSelector: @selector(parser:foundCharacters:)]) [_delegate parser: self foundCharacters: characters]; objc_autoreleasePoolPop(pool); } - [_cache removeAllItems]; + [_buffer removeAllItems]; *last = *i + 1; _state = OF_XMLPARSER_TAG_OPENED; } @@ -492,12 +492,12 @@ _level = 1; else if (_level == 1 && buffer[*i] == '>') { void *pool = objc_autoreleasePoolPush(); OFString *PI; - cache_append(_cache, buffer + *last, _encoding, *i - *last); - PI = transform_string(_cache, 1, NO, nil); + buffer_append(_buffer, buffer + *last, _encoding, *i - *last); + PI = transform_string(_buffer, 1, NO, nil); if ([PI isEqual: @"xml"] || [PI hasPrefix: @"xml "] || [PI hasPrefix: @"xml\t"] || [PI hasPrefix: @"xml\r"] || [PI hasPrefix: @"xml\n"]) if (![self OF_parseXMLProcessingInstructions: PI]) @@ -510,11 +510,11 @@ [_delegate parser: self foundProcessingInstructions: PI]; objc_autoreleasePoolPop(pool); - [_cache removeAllItems]; + [_buffer removeAllItems]; *last = *i + 1; _state = OF_XMLPARSER_OUTSIDE_TAG; } else _level = 0; @@ -524,37 +524,38 @@ - (void)OF_parseInTagNameWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { void *pool; - const char *cacheCString, *tmp; - size_t length, cacheLength; - OFString *cacheString; + const char *bufferCString, *tmp; + size_t length, bufferLength; + OFString *bufferString; if (buffer[*i] != ' ' && buffer[*i] != '\t' && buffer[*i] != '\n' && buffer[*i] != '\r' && buffer[*i] != '>' && buffer[*i] != '/') return; if ((length = *i - *last) > 0) - cache_append(_cache, buffer + *last, _encoding, length); + buffer_append(_buffer, buffer + *last, _encoding, length); pool = objc_autoreleasePoolPush(); - cacheCString = [_cache items]; - cacheLength = [_cache count]; - cacheString = [OFString stringWithUTF8String: cacheCString - length: cacheLength]; + bufferCString = [_buffer items]; + bufferLength = [_buffer count]; + bufferString = [OFString stringWithUTF8String: bufferCString + length: bufferLength]; - if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) { + if ((tmp = memchr(bufferCString, ':', bufferLength)) != NULL) { _name = [[OFString alloc] initWithUTF8String: tmp + 1 - length: cacheLength - (tmp - cacheCString) - 1]; + length: bufferLength - + (tmp - bufferCString) - 1]; _prefix = [[OFString alloc] - initWithUTF8String: cacheCString - length: tmp - cacheCString]; + initWithUTF8String: bufferCString + length: tmp - bufferCString]; } else { - _name = [cacheString copy]; + _name = [bufferString copy]; _prefix = nil; } if (buffer[*i] == '>' || buffer[*i] == '/') { OFString *namespace; @@ -583,11 +584,11 @@ namespace: namespace]; if ([_previous count] == 0) _finishedParsing = YES; } else - [_previous addObject: cacheString]; + [_previous addObject: bufferString]; [_name release]; [_prefix release]; _name = _prefix = nil; @@ -600,57 +601,58 @@ if (buffer[*i] != '/') [_namespaces addObject: [OFMutableDictionary dictionary]]; objc_autoreleasePoolPop(pool); - [_cache removeAllItems]; + [_buffer removeAllItems]; *last = *i + 1; } /* Inside a close tag, no name yet */ - (void)OF_parseInCloseTagNameWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { void *pool; - const char *cacheCString, *tmp; - size_t length, cacheLength; - OFString *cacheString, *namespace; + const char *bufferCString, *tmp; + size_t length, bufferLength; + OFString *bufferString, *namespace; if (buffer[*i] != ' ' && buffer[*i] != '\t' && buffer[*i] != '\n' && buffer[*i] != '\r' && buffer[*i] != '>') return; if ((length = *i - *last) > 0) - cache_append(_cache, buffer + *last, _encoding, length); + buffer_append(_buffer, buffer + *last, _encoding, length); pool = objc_autoreleasePoolPush(); - cacheCString = [_cache items]; - cacheLength = [_cache count]; - cacheString = [OFString stringWithUTF8String: cacheCString - length: cacheLength]; + bufferCString = [_buffer items]; + bufferLength = [_buffer count]; + bufferString = [OFString stringWithUTF8String: bufferCString + length: bufferLength]; - if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) { + if ((tmp = memchr(bufferCString, ':', bufferLength)) != NULL) { _name = [[OFString alloc] initWithUTF8String: tmp + 1 - length: cacheLength - (tmp - cacheCString) - 1]; + length: bufferLength - + (tmp - bufferCString) - 1]; _prefix = [[OFString alloc] - initWithUTF8String: cacheCString - length: tmp - cacheCString]; + initWithUTF8String: bufferCString + length: tmp - bufferCString]; } else { - _name = [cacheString copy]; + _name = [bufferString copy]; _prefix = nil; } - if (![[_previous lastObject] isEqual: cacheString]) + if (![[_previous lastObject] isEqual: bufferString]) @throw [OFMalformedXMLException exceptionWithClass: [self class] parser: self]; [_previous removeLastObject]; - [_cache removeAllItems]; + [_buffer removeAllItems]; namespace = namespace_for_prefix(_prefix, _namespaces); if (_prefix != nil && namespace == nil) @throw [OFUnboundNamespaceException exceptionWithClass: [self class] @@ -760,46 +762,47 @@ - (void)OF_parseInAttributeNameWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { void *pool; - OFMutableString *cacheString; - const char *cacheCString, *tmp; - size_t length, cacheLength; + OFMutableString *bufferString; + const char *bufferCString, *tmp; + size_t length, bufferLength; if (buffer[*i] != '=') return; if ((length = *i - *last) > 0) - cache_append(_cache, buffer + *last, _encoding, length); + buffer_append(_buffer, buffer + *last, _encoding, length); pool = objc_autoreleasePoolPush(); - cacheString = [OFMutableString stringWithUTF8String: [_cache items] - length: [_cache count]]; - [cacheString deleteEnclosingWhitespaces]; + bufferString = [OFMutableString stringWithUTF8String: [_buffer items] + length: [_buffer count]]; + [bufferString deleteEnclosingWhitespaces]; /* Prevent a useless copy later */ - [cacheString makeImmutable]; + [bufferString makeImmutable]; - cacheCString = [cacheString UTF8String]; - cacheLength = [cacheString UTF8StringLength]; + bufferCString = [bufferString UTF8String]; + bufferLength = [bufferString UTF8StringLength]; - if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) { + if ((tmp = memchr(bufferCString, ':', bufferLength)) != NULL) { _attributeName = [[OFString alloc] initWithUTF8String: tmp + 1 - length: cacheLength - (tmp - cacheCString) - 1]; + length: bufferLength - + (tmp - bufferCString) - 1]; _attributePrefix = [[OFString alloc] - initWithUTF8String: cacheCString - length: tmp - cacheCString]; + initWithUTF8String: bufferCString + length: tmp - bufferCString]; } else { - _attributeName = [cacheString copy]; + _attributeName = [bufferString copy]; _attributePrefix = nil; } objc_autoreleasePoolPop(pool); - [_cache removeAllItems]; + [_buffer removeAllItems]; *last = *i + 1; _state = OF_XMLPARSER_EXPECT_DELIM; } @@ -833,14 +836,14 @@ if (buffer[*i] != _delimiter) return; if ((length = *i - *last) > 0) - cache_append(_cache, buffer + *last, _encoding, length); + buffer_append(_buffer, buffer + *last, _encoding, length); pool = objc_autoreleasePoolPush(); - attributeValue = transform_string(_cache, 0, YES, self); + attributeValue = transform_string(_buffer, 0, YES, self); if (_attributePrefix == nil && [_attributeName isEqual: @"xmlns"]) [[_namespaces lastObject] setObject: attributeValue forKey: @""]; if ([_attributePrefix isEqual: @"xmlns"]) @@ -852,11 +855,11 @@ namespace: _attributePrefix stringValue: attributeValue]]; objc_autoreleasePoolPop(pool); - [_cache removeAllItems]; + [_buffer removeAllItems]; [_attributeName release]; [_attributePrefix release]; _attributeName = _attributePrefix = nil; *last = *i + 1; @@ -958,20 +961,20 @@ return; } pool = objc_autoreleasePoolPush(); - cache_append(_cache, buffer + *last, _encoding, *i - *last); - CDATA = transform_string(_cache, 2, NO, nil); + buffer_append(_buffer, buffer + *last, _encoding, *i - *last); + CDATA = transform_string(_buffer, 2, NO, nil); if ([_delegate respondsToSelector: @selector(parser:foundCDATA:)]) [_delegate parser: self foundCDATA: CDATA]; objc_autoreleasePoolPop(pool); - [_cache removeAllItems]; + [_buffer removeAllItems]; *last = *i + 1; _state = OF_XMLPARSER_OUTSIDE_TAG; } @@ -1013,20 +1016,20 @@ @throw [OFMalformedXMLException exceptionWithClass: [self class] parser: self]; pool = objc_autoreleasePoolPush(); - cache_append(_cache, buffer + *last, _encoding, *i - *last); - comment = transform_string(_cache, 2, NO, nil); + buffer_append(_buffer, buffer + *last, _encoding, *i - *last); + comment = transform_string(_buffer, 2, NO, nil); if ([_delegate respondsToSelector: @selector(parser:foundComment:)]) [_delegate parser: self foundComment: comment]; objc_autoreleasePoolPop(pool); - [_cache removeAllItems]; + [_buffer removeAllItems]; *last = *i + 1; _state = OF_XMLPARSER_OUTSIDE_TAG; }