From 3d003446399837c6101309742264d32f516489c4 Mon Sep 17 00:00:00 2001 From: Dirk Zimmermann Date: Thu, 29 Apr 2021 09:33:41 +0200 Subject: [PATCH] IOS-2794 Don't use subdataUncopiedWithRange --- .../PantomimeFramework/NSData+Extensions.h | 5 ----- .../Framework/Pantomime/NSData+Extensions.m | 16 +--------------- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/PantomimeFramework/PantomimeFramework/NSData+Extensions.h b/PantomimeFramework/PantomimeFramework/NSData+Extensions.h index decb539..ad984e9 100644 --- a/PantomimeFramework/PantomimeFramework/NSData+Extensions.h +++ b/PantomimeFramework/PantomimeFramework/NSData+Extensions.h @@ -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: diff --git a/pantomime-lib/Framework/Pantomime/NSData+Extensions.m b/pantomime-lib/Framework/Pantomime/NSData+Extensions.m index 1640495..e35f2a5 100644 --- a/pantomime-lib/Framework/Pantomime/NSData+Extensions.m +++ b/pantomime-lib/Framework/Pantomime/NSData+Extensions.m @@ -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++;