@@ -29,10 +29,11 @@ #endif #import "OFIRI.h" #import "OFIRIHandler.h" #import "OFStream.h" #import "OFString.h" +#import "OFSubdata.h" #import "OFSystemInfo.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" @@ -561,21 +562,22 @@ return hash; } - (OFData *)subdataWithRange: (OFRange)range { - size_t itemSize; - if (range.length > SIZE_MAX - range.location || range.location + range.length > self.count) @throw [OFOutOfRangeException exception]; - itemSize = self.itemSize; + if (![self isKindOfClass: [OFMutableData class]]) + return [[[OFSubdata alloc] initWithData: self + range: range] autorelease]; + return [OFData dataWithItems: (const unsigned char *)self.items + - (range.location * itemSize) - count: range.length - itemSize: itemSize]; + (range.location * self.itemSize) + count: self.count + itemSize: self.itemSize]; } - (OFString *)description { OFMutableString *ret = [OFMutableString stringWithString: @"<"];