@@ -120,14 +120,12 @@ capacity: (size_t)capacity { self = [super init]; if (itemSize == 0) { - Class c = [self class]; [self release]; - @throw [OFInvalidArgumentException exceptionWithClass: c - selector: _cmd]; + @throw [OFInvalidArgumentException exception]; } _items = [self allocMemoryWithSize: itemSize count: capacity]; @@ -143,12 +141,11 @@ OFFile *file = [[OFFile alloc] initWithPath: path mode: @"rb"]; off_t size = [OFFile sizeOfFileAtPath: path]; if (size > SIZE_MAX) - @throw [OFOutOfRangeException - exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; self = [self initWithItemSize: 1 capacity: (size_t)size]; @try { @@ -204,13 +201,12 @@ request = [OFHTTPRequest requestWithURL: URL]; reply = [client performRequest: request]; if ([reply statusCode] != 200) @throw [OFHTTPRequestFailedException - exceptionWithClass: [request class] - request: request - reply: reply]; + exceptionWithRequest: request + reply: reply]; /* * TODO: This can be optimized by allocating a data array with the * capacity from the Content-Length header. */ @@ -217,14 +213,13 @@ self = [[reply readDataArrayTillEndOfStream] retain]; headers = [reply headers]; if ((contentLength = [headers objectForKey: @"Content-Length"]) != nil) if ([self count] != (size_t)[contentLength decimalValue]) - @throw [OFTruncatedDataException - exceptionWithClass: [self class]]; + @throw [OFTruncatedDataException exception]; #else - @throw [OFUnsupportedProtocolException exceptionWithClass: c]; + @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; #endif objc_autoreleasePoolPop(pool); return self; @@ -241,12 +236,11 @@ _itemSize = 1; _count = [string cStringLengthWithEncoding: OF_STRING_ENCODING_ASCII]; if (_count % 2 != 0) - @throw [OFInvalidFormatException - exceptionWithClass: [self class]]; + @throw [OFInvalidFormatException exception]; _count /= 2; cString = [string cStringWithEncoding: OF_STRING_ENCODING_ASCII]; _items = [self allocMemoryWithSize: _count]; @@ -261,22 +255,20 @@ else if (c1 >= 'a' && c1 <= 'f') byte = (c1 - 'a' + 10) << 4; else if (c1 >= 'A' && c1 <= 'F') byte = (c1 - 'A' + 10) << 4; else - @throw [OFInvalidFormatException - exceptionWithClass: [self class]]; + @throw [OFInvalidFormatException exception]; if (c2 >= '0' && c2 <= '9') byte |= c2 - '0'; else if (c2 >= 'a' && c2 <= 'f') byte |= c2 - 'a' + 10; else if (c2 >= 'A' && c2 <= 'F') byte |= c2 - 'A' + 10; else - @throw [OFInvalidFormatException - exceptionWithClass: [self class]]; + @throw [OFInvalidFormatException exception]; _items[i] = byte; } } @catch (id e) { [self release]; @@ -292,15 +284,12 @@ capacity: [string length] / 3]; @try { if (!of_base64_decode(self, [string cStringWithEncoding: OF_STRING_ENCODING_ASCII], [string - cStringLengthWithEncoding: OF_STRING_ENCODING_ASCII])) { - Class c = [self class]; - [self release]; - @throw [OFInvalidFormatException exceptionWithClass: c]; - } + cStringLengthWithEncoding: OF_STRING_ENCODING_ASCII])) + @throw [OFInvalidFormatException exception]; } @catch (id e) { [self release]; @throw e; } @@ -313,13 +302,11 @@ void *pool = objc_autoreleasePoolPush(); OFString *stringValue; if (![[element name] isEqual: [self className]] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) - @throw [OFInvalidArgumentException - exceptionWithClass: [self class] - selector: _cmd]; + @throw [OFInvalidArgumentException exception]; stringValue = [element stringValue]; self = [self initWithBase64EncodedString: stringValue]; @@ -348,11 +335,11 @@ } - (void*)itemAtIndex: (size_t)index { if (index >= _count) - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; return _items + index * _itemSize; } - (void*)firstItem @@ -372,11 +359,11 @@ } - (void)addItem: (const void*)item { if (SIZE_MAX - _count < 1) - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; if (_count + 1 > _capacity) { _items = [self resizeMemory: _items size: _itemSize count: _count + 1]; @@ -398,11 +385,11 @@ - (void)addItems: (const void*)items count: (size_t)count { if (count > SIZE_MAX - count) - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; if (_count + count > _capacity) { _items = [self resizeMemory: _items size: _itemSize count: _count + count]; @@ -416,11 +403,11 @@ - (void)insertItems: (const void*)items atIndex: (size_t)index count: (size_t)count { if (count > SIZE_MAX - _count || index > _count) - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; if (_count + count > _capacity) { _items = [self resizeMemory: _items size: _itemSize count: _count + count]; @@ -441,11 +428,11 @@ - (void)removeItemsInRange: (of_range_t)range { if (range.length > SIZE_MAX - range.location || range.location + range.length > _count) - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; memmove(_items + range.location * _itemSize, _items + (range.location + range.length) * _itemSize, (_count - range.location - range.length) * _itemSize); @@ -519,19 +506,16 @@ OFDataArray *dataArray; int comparison; size_t count, minCount; if (![object isKindOfClass: [OFDataArray class]]) - @throw [OFInvalidArgumentException - exceptionWithClass: [self class] - selector: _cmd]; + @throw [OFInvalidArgumentException exception]; + dataArray = (OFDataArray*)object; if ([dataArray itemSize] != _itemSize) - @throw [OFInvalidArgumentException - exceptionWithClass: [self class] - selector: _cmd]; + @throw [OFInvalidArgumentException exception]; count = [dataArray count]; minCount = (_count > count ? count : _count); if ((comparison = memcmp(_items, [dataArray items], @@ -621,12 +605,11 @@ { void *pool; OFXMLElement *element; if (_itemSize != 1) - @throw [OFInvalidArgumentException - exceptionWithClass: [self class]]; + @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS @@ -642,13 +625,11 @@ - (OFDataArray*)messagePackRepresentation { OFDataArray *data; if (_itemSize != 1) - @throw [OFInvalidArgumentException - exceptionWithClass: [self class] - selector: _cmd]; + @throw [OFInvalidArgumentException exception]; if (_count <= UINT8_MAX) { uint8_t type = 0xC4; uint8_t tmp = (uint8_t)_count; @@ -676,11 +657,11 @@ [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; [data addItems: _items count: _count]; return data; @@ -702,11 +683,11 @@ - (void)addItem: (const void*)item { size_t size, lastPageByte; if (SIZE_MAX - _count < 1 || _count + 1 > SIZE_MAX / _itemSize) - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; lastPageByte = [OFSystemInfo pageSize] - 1; size = ((_count + 1) * _itemSize + lastPageByte) & ~lastPageByte; if (size > _capacity) { @@ -725,11 +706,11 @@ count: (size_t)count { size_t size, lastPageByte; if (count > SIZE_MAX - _count || _count + count > SIZE_MAX / _itemSize) - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; lastPageByte = [OFSystemInfo pageSize] - 1; size = ((_count + count) * _itemSize + lastPageByte) & ~lastPageByte; if (size > _capacity) { @@ -750,11 +731,11 @@ { size_t size, lastPageByte; if (count > SIZE_MAX - _count || index > _count || _count + count > SIZE_MAX / _itemSize) - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; lastPageByte = [OFSystemInfo pageSize] - 1; size = ((_count + count) * _itemSize + lastPageByte) & ~lastPageByte; if (size > _capacity) { @@ -775,11 +756,11 @@ { size_t pageSize, size; if (range.length > SIZE_MAX - range.location || range.location + range.length > _count) - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + @throw [OFOutOfRangeException exception]; memmove(_items + range.location * _itemSize, _items + (range.location + range.length) * _itemSize, (_count - range.location - range.length) * _itemSize);