IOS-2794 Don't use subdataUncopiedWithRange

IOS-2794
Dirk Zimmermann 2 years ago
parent e3bc83d472
commit 3d00344639

@ -158,11 +158,6 @@
*/
- (NSData *) subdataToIndex: (NSUInteger) theIndex;
/// Like `subDataWithRange`, but doesn't copy bytes, and instead points to the bytes from the original.
/// @note The caller has to make sure that the returned `NSData` does not exist longer than the `NSData` that owns
/// the actual bytes.
- (NSData *)subdataUncopiedWithRange:(NSRange)range;
/**
@discussion Simple method to trim the leading and trailing whitespaces (characters with no visible
representation). Cahracters currently taken into accout are:

@ -437,20 +437,6 @@ static const char *hexDigit = "0123456789ABCDEF";
return [self subdataWithRange: NSMakeRange(0, theIndex)];
}
- (NSData *)subdataUncopiedWithRange:(NSRange)range
{
const char *theBytes = [self bytes];
const char *newBytes = theBytes + range.location;
// Let the NSData point to existing bytes without copy,
// and don't do anything to free them
return [[NSData alloc] initWithBytesNoCopy:(void *) newBytes
length:range.length
deallocator:^(void * _Nonnull bytes, NSUInteger length) {
// ignore, don't free anything
}];
}
- (NSData *)dataByTrimmingWhiteSpaces
{
const char *bytes = [self bytes];
@ -789,7 +775,7 @@ static const char *hexDigit = "0123456789ABCDEF";
NSUInteger count = 0;
while (r2.length) {
block([self subdataUncopiedWithRange:NSMakeRange(r1.location, r2.location - r1.location)],
block([self subdataWithRange:NSMakeRange(r1.location, r2.location - r1.location)],
count,
NO);
count++;

Loading…
Cancel
Save