Index: src/OFHTTPRequest.m ================================================================== --- src/OFHTTPRequest.m +++ src/OFHTTPRequest.m @@ -23,10 +23,11 @@ #import "OFURL.h" #import "OFTCPSocket.h" #import "OFDictionary.h" #import "OFAutoreleasePool.h" #import "OFExceptions.h" +#import "macros.h" Class of_http_request_tls_socket_class = Nil; @implementation OFHTTPRequest + request @@ -56,18 +57,16 @@ [super dealloc]; } - (void)setURL: (OFURL*)url { - OFURL *old = URL; - URL = [url copy]; - [old release]; + OF_SETTER(URL, url, YES, YES) } - (OFURL*)URL { - return [[URL copy] autorelease]; + OF_GETTER(URL, YES) } - (void)setRequestType: (of_http_request_type_t)type { requestType = type; @@ -78,30 +77,26 @@ return requestType; } - (void)setQueryString: (OFString*)qs { - OFString *old = queryString; - queryString = [qs copy]; - [old release]; + OF_SETTER(queryString, qs, YES, YES) } - (OFString*)queryString { - return [[queryString copy] autorelease]; + OF_GETTER(queryString, YES) } - (void)setHeaders: (OFDictionary*)headers_ { - OFDictionary *old = headers; - headers = [headers_ copy]; - [old release]; + OF_SETTER(headers, headers_, YES, YES) } - (OFDictionary*)headers { - return [[headers copy] autorelease]; + OF_GETTER(headers, YES) } - (OFHTTPRequestResult*)perform { return [self performWithRedirects: 10]; Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -410,9 +410,11 @@ @end #ifdef __cplusplus extern "C" { #endif +extern id objc_getProperty(id, SEL, ptrdiff_t, BOOL); +extern void objc_setProperty(id, SEL, ptrdiff_t, id, BOOL, BOOL); extern size_t of_pagesize; #ifdef __cplusplus } #endif Index: src/OFURL.m ================================================================== --- src/OFURL.m +++ src/OFURL.m @@ -371,11 +371,11 @@ return new; } - (OFString*)scheme { - return [[scheme copy] autorelease]; + OF_GETTER(scheme, YES) } - (void)setScheme: (OFString*)scheme_ { if (![scheme_ isEqual: @"http"] && ![scheme_ isEqual: @"https"]) @@ -387,18 +387,16 @@ [old release]; } - (OFString*)host { - return [[host copy] autorelease]; + OF_GETTER(host, YES) } - (void)setHost: (OFString*)host_ { - OFString *old = host; - host = [host_ copy]; - [old release]; + OF_SETTER(host, host_, YES, YES) } - (uint16_t)port { return port; @@ -409,35 +407,31 @@ port = port_; } - (OFString*)user { - return [[user copy] autorelease]; + OF_GETTER(user, YES) } - (void)setUser: (OFString*)user_ { - OFString *old = user; - user = [user_ copy]; - [old release]; + OF_SETTER(user, user_, YES, YES) } - (OFString*)password { - return [[password copy] autorelease]; + OF_GETTER(password, YES) } - (void)setPassword: (OFString*)password_ { - OFString *old = password; - password = [password_ copy]; - [old release]; + OF_SETTER(password, password_, YES, YES) } - (OFString*)path { - return [[path copy] autorelease]; + OF_GETTER(path, YES) } - (void)setPath: (OFString*)path_ { OFString *old; @@ -452,42 +446,36 @@ [old release]; } - (OFString*)parameters { - return [[parameters copy] autorelease]; + OF_GETTER(parameters, YES) } - (void)setParameters: (OFString*)parameters_ { - OFString *old = parameters; - parameters = [parameters_ copy]; - [old release]; + OF_SETTER(parameters, parameters_, YES, YES) } - (OFString*)query { - return [[query copy] autorelease]; + OF_GETTER(query, YES) } - (void)setQuery: (OFString*)query_ { - OFString *old = query; - query = [query_ copy]; - [old release]; + OF_SETTER(query, query_, YES, YES) } - (OFString*)fragment { - return [[fragment copy] autorelease]; + OF_GETTER(fragment, YES) } - (void)setFragment: (OFString*)fragment_ { - OFString *old = fragment; - fragment = [fragment_ copy]; - [old release]; + OF_SETTER(fragment, fragment_, YES, YES) } - (OFString*)description { OFMutableString *desc = [OFMutableString stringWithFormat: @"%@://", Index: src/macros.h ================================================================== --- src/macros.h +++ src/macros.h @@ -69,10 +69,16 @@ # define OF_PATH_DELIM '/' #else # define OF_PATH_DELIM '\\' #endif +#define OF_IVAR_OFFSET(ivar) ((char*)&ivar - (char*)self) +#define OF_GETTER(ivar, atomic) \ + return objc_getProperty(self, _cmd, OF_IVAR_OFFSET(ivar), atomic); +#define OF_SETTER(ivar, value, atomic, copy) \ + objc_setProperty(self, _cmd, OF_IVAR_OFFSET(ivar), value, atomic, copy); + static OF_INLINE uint16_t OF_CONST_FUNC of_bswap16_const(uint16_t i) { return (i & UINT16_C(0xFF00)) >> 8 | (i & UINT16_C(0x00FF)) << 8;