Skip to content

Commit eee5663

Browse files
committed
Major refactoring of library. KissXML is now faster and fully read-access thread-safe.
1 parent a1218bf commit eee5663

25 files changed

+1576
-1152
lines changed

DDXMLPrivate.h

Lines changed: 0 additions & 79 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

NSStringAdditions.h renamed to KissXML/Categories/NSString+DDXML.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#import <libxml/tree.h>
33

44

5-
@interface NSString (NSStringAdditions)
5+
@interface NSString (DDXML)
66

77
/**
88
* xmlChar - A basic replacement for char, a byte in a UTF-8 encoded string.

NSStringAdditions.m renamed to KissXML/Categories/NSString+DDXML.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#import "NSStringAdditions.h"
1+
#import "NSString+DDXML.h"
22

33

4-
@implementation NSString (NSStringAdditions)
4+
@implementation NSString (DDXML)
55

66
- (const xmlChar *)xmlChar
77
{

DDXML.h renamed to KissXML/DDXML.h

File renamed without changes.
File renamed without changes.

DDXMLDocument.m renamed to KissXML/DDXMLDocument.m

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
1-
#import "DDXMLDocument.h"
2-
#import "NSStringAdditions.h"
31
#import "DDXMLPrivate.h"
2+
#import "NSString+DDXML.h"
43

54

65
@implementation DDXMLDocument
76

87
/**
98
* Returns a DDXML wrapper object for the given primitive node.
109
* The given node MUST be non-NULL and of the proper type.
11-
*
12-
* If the wrapper object already exists, it is retained/autoreleased and returned.
13-
* Otherwise a new wrapper object is alloc/init/autoreleased and returned.
1410
**/
15-
+ (id)nodeWithPrimitive:(xmlKindPtr)kindPtr
11+
+ (id)nodeWithDocPrimitive:(xmlDocPtr)doc freeOnDealloc:(BOOL)flag
1612
{
17-
// If a wrapper object already exists, the _private variable is pointing to it.
18-
19-
xmlDocPtr doc = (xmlDocPtr)kindPtr;
20-
if(doc->_private == NULL)
21-
return [[[DDXMLDocument alloc] initWithCheckedPrimitive:kindPtr] autorelease];
22-
else
23-
return [[((DDXMLDocument *)(doc->_private)) retain] autorelease];
13+
return [[[DDXMLDocument alloc] initWithDocPrimitive:doc freeOnDealloc:flag] autorelease];
2414
}
2515

26-
/**
27-
* Returns a DDXML wrapper object for the given primitive node.
28-
* The given node MUST be non-NULL and of the proper type.
29-
*
30-
* The given node is checked, meaning a wrapper object for it does not already exist.
31-
**/
32-
- (id)initWithCheckedPrimitive:(xmlKindPtr)kindPtr
16+
- (id)initWithDocPrimitive:(xmlDocPtr)doc freeOnDealloc:(BOOL)flag
3317
{
34-
self = [super initWithCheckedPrimitive:kindPtr];
18+
self = [super initWithPrimitive:(xmlKindPtr)doc freeOnDealloc:flag];
3519
return self;
3620
}
3721

22+
+ (id)nodeWithPrimitive:(xmlKindPtr)kindPtr freeOnDealloc:(BOOL)flag
23+
{
24+
// Promote initializers which use proper parameter types to enable compiler to catch more mistakes
25+
NSAssert(NO, @"Use nodeWithDocPrimitive:freeOnDealloc:");
26+
27+
return nil;
28+
}
29+
30+
- (id)initWithPrimitive:(xmlKindPtr)kindPtr freeOnDealloc:(BOOL)flag
31+
{
32+
// Promote initializers which use proper parameter types to enable compiler to catch more mistakes.
33+
NSAssert(NO, @"Use initWithDocPrimitive:freeOnDealloc:");
34+
35+
[self release];
36+
return nil;
37+
}
38+
3839
/**
3940
* Initializes and returns a DDXMLDocument object created from an NSData object.
4041
*
@@ -43,7 +44,9 @@ - (id)initWithCheckedPrimitive:(xmlKindPtr)kindPtr
4344
**/
4445
- (id)initWithXMLString:(NSString *)string options:(NSUInteger)mask error:(NSError **)error
4546
{
46-
return [self initWithData:[string dataUsingEncoding:NSUTF8StringEncoding] options:mask error:error];
47+
return [self initWithData:[string dataUsingEncoding:NSUTF8StringEncoding]
48+
options:mask
49+
error:error];
4750
}
4851

4952
/**
@@ -54,9 +57,9 @@ - (id)initWithXMLString:(NSString *)string options:(NSUInteger)mask error:(NSErr
5457
**/
5558
- (id)initWithData:(NSData *)data options:(NSUInteger)mask error:(NSError **)error
5659
{
57-
if(data == nil || [data length] == 0)
60+
if (data == nil || [data length] == 0)
5861
{
59-
if(error) *error = [NSError errorWithDomain:@"DDXMLErrorDomain" code:0 userInfo:nil];
62+
if (error) *error = [NSError errorWithDomain:@"DDXMLErrorDomain" code:0 userInfo:nil];
6063

6164
[self release];
6265
return nil;
@@ -70,15 +73,15 @@ - (id)initWithData:(NSData *)data options:(NSUInteger)mask error:(NSError **)err
7073
xmlKeepBlanksDefault(0);
7174

7275
xmlDocPtr doc = xmlParseMemory([data bytes], [data length]);
73-
if(doc == NULL)
76+
if (doc == NULL)
7477
{
75-
if(error) *error = [NSError errorWithDomain:@"DDXMLErrorDomain" code:1 userInfo:nil];
78+
if (error) *error = [NSError errorWithDomain:@"DDXMLErrorDomain" code:1 userInfo:nil];
7679

7780
[self release];
7881
return nil;
7982
}
8083

81-
return [self initWithCheckedPrimitive:(xmlKindPtr)doc];
84+
return [self initWithDocPrimitive:doc freeOnDealloc:YES];
8285
}
8386

8487
/**
@@ -92,8 +95,8 @@ - (DDXMLElement *)rootElement
9295

9396
xmlNodePtr rootNode = xmlDocGetRootElement(doc);
9497

95-
if(rootNode != NULL)
96-
return [DDXMLElement nodeWithPrimitive:(xmlKindPtr)rootNode];
98+
if (rootNode != NULL)
99+
return [DDXMLElement nodeWithElementPrimitive:rootNode freeOnDealloc:NO];
97100
else
98101
return nil;
99102
}
File renamed without changes.

0 commit comments

Comments
 (0)