diff --git a/ChangeLog b/ChangeLog index 1e4f2bb7d..9d5a3e2db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2012-01-02 22:26-EST Gregory John Casamento + + * Headers/Foundation/NSXMLElement.h: Change _attributes to be + a NSMutableDictionary instead of an NSMutableArray. + * Source/NSXMLElement.m: Change implementation of some methods + to use an NSMutableDictionary instead of arrays. Initialize + ivars in initializer. + * Source/NSXMLPrivate.h: Remove redundant method. + 2012-01-02 Fred Kiefer * Source/GSSocketStream.m (-initWithInput:output:): Attempt to diff --git a/Headers/Foundation/NSXMLElement.h b/Headers/Foundation/NSXMLElement.h index 32ea3c4b2..5cec2ecf6 100644 --- a/Headers/Foundation/NSXMLElement.h +++ b/Headers/Foundation/NSXMLElement.h @@ -32,8 +32,7 @@ extern "C" { #endif - -@class NSDictionary, NSEnumerator, NSMutableArray; +@class NSDictionary, NSEnumerator, NSMutableArray, NSMutableDictionary; /** * Represents an XML element.
@@ -42,14 +41,12 @@ extern "C" { { #if GS_EXPOSE(NSXMLElement) @protected - // NSString *_name; - NSMutableArray *_attributes; + NSMutableDictionary *_attributes; NSMutableArray *_namespaces; NSMutableArray *_children; BOOL _childrenHaveMutated; NSString *_URI; NSInteger _prefixIndex; - NSString *_value; #endif } diff --git a/Source/NSXMLElement.m b/Source/NSXMLElement.m index 1f9d4113c..973f07325 100644 --- a/Source/NSXMLElement.m +++ b/Source/NSXMLElement.m @@ -48,13 +48,20 @@ if ((self = [super initWithKind:NSXMLElementKind]) != nil) { ASSIGN(_name, name); + _attributes = [[NSMutableDictionary alloc] initWithCapacity: 10]; + _namespaces = [[NSMutableArray alloc] initWithCapacity: 10]; + _children = [[NSMutableArray alloc] initWithCapacity: 10]; + _URI = nil; } return self; } - (id) initWithName: (NSString*)name stringValue: (NSString*)string { - [self notImplemented: _cmd]; + if([self initWithName: name URI: nil] != nil) + { + [self setObjectValue: string]; + } return nil; } @@ -78,24 +85,13 @@ - (void) addAttribute: (NSXMLNode*)attribute { - [_attributes addObject: attribute]; + [_attributes setObject: attribute + forKey: [attribute name]]; } - (void) removeAttributeForName: (NSString*)name { - NSEnumerator *en = [_attributes objectEnumerator]; - NSXMLNode *node = nil; - int index = 0; - - while ((node = [en nextObject]) != nil) - { - NSString *nodeName = [node name]; - if ([nodeName isEqualToString: name]) - { - [_attributes removeObjectAtIndex: index]; - } - index++; - } + [_attributes removeObjectForKey: name]; } - (void) setAttributes: (NSArray*)attributes @@ -111,35 +107,17 @@ - (void) setAttributesAsDictionary: (NSDictionary*)attributes { - NSEnumerator *ken = [attributes keyEnumerator]; - id key = nil; - while ((key = [ken nextObject]) != nil) - { - id value = [attributes objectForKey: key]; - NSXMLNode *node = [NSXMLNode attributeWithName: key - stringValue: value]; - [self addAttribute: node]; - } + ASSIGN(_attributes, [attributes mutableCopy]); } - (NSArray*) attributes { - return _attributes; + return [_attributes allValues]; } - (NSXMLNode*) attributeForName: (NSString*)name { - NSEnumerator *enumerator = [[self attributes] objectEnumerator]; - NSXMLNode *attribute; - - while ((attribute = [enumerator nextObject]) != nil) - { - if ([name isEqualToString: [attribute name]] == YES) - { - return attribute; - } - } - return nil; + return [_attributes objectForKey: name]; } - (NSXMLNode*) attributeForLocalName: (NSString*)localName diff --git a/Source/NSXMLPrivate.h b/Source/NSXMLPrivate.h index b53249711..be78b6081 100644 --- a/Source/NSXMLPrivate.h +++ b/Source/NSXMLPrivate.h @@ -76,6 +76,5 @@ #endif @interface NSXMLNode (Private) -- (void) setName: (NSString *)name; - (void) setParent: (NSXMLNode *)node; @end