From d6bb6deff602ec23cf8bc35ba7c53a1fd8275f30 Mon Sep 17 00:00:00 2001 From: rfm Date: Fri, 2 Feb 2024 15:40:44 +0000 Subject: [PATCH] fix small bug and add optimisation --- ChangeLog | 7 +++++++ Source/Additions/GSMime.m | 6 +++--- Source/NSString.m | 33 ++++++++++++++++++++++++--------- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index e9a5211d3..5ac950deb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2024-02-02 Richard Frith-Macdonald + + Source/NSString.m: Return empty string of correct class when loading + from an empty file or URL. + Source/Additions/GSMime.m: minor optimisation usng more efficient + method to append headers to mutable data object. + 2024-02-01 Frederik Seiffert * Source/NSLocale.m: Fix -countryCode incorrectly returning language diff --git a/Source/Additions/GSMime.m b/Source/Additions/GSMime.m index 2b73562d8..b44f99b01 100644 --- a/Source/Additions/GSMime.m +++ b/Source/Additions/GSMime.m @@ -3544,7 +3544,7 @@ - (void) addToBuffer: (NSMutableData*)buf } } } - [buf appendData: [self rawMimeDataPreservingCase: YES foldedAt: 0]]; + [self rawMimeDataPreservingCase: YES foldedAt: 0 to: buf]; if (masked && *masked) { NSUInteger len = [buf length]; @@ -7290,7 +7290,7 @@ - (NSMutableData*) rawMimeData: (BOOL)isOuter foldedAt: (NSUInteger)fold enumerator = [headers objectEnumerator]; while ((hdr = [enumerator nextObject]) != nil) { - [md appendData: [hdr rawMimeDataPreservingCase: NO foldedAt: fold]]; + [hdr rawMimeDataPreservingCase: NO foldedAt: fold to: md]; } if (partData != nil) @@ -8085,7 +8085,7 @@ - (void) encodePart: (GSMimeDocument*)document to: (NSMutableData*)md [document setHeader: @"Content-Transfer-Encoding" value: enc parameters: nil]; - } + } } } diff --git a/Source/NSString.m b/Source/NSString.m index 1842fa801..3a2315396 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -1542,8 +1542,10 @@ - (id) initWithContentsOfFile: (NSString*)path if (len == 0) { RELEASE(d); - DESTROY(self); - return @""; + return [self initWithBytesNoCopy: (char *)"" + length: 0 + encoding: NSASCIIStringEncoding + freeWhenDone: NO]; } data_bytes = [d bytes]; if ((data_bytes != NULL) && (len >= 2)) @@ -1616,8 +1618,10 @@ - (id) initWithContentsOfFile: (NSString*)path if (len == 0) { RELEASE(d); - DESTROY(self); - return @""; + return [self initWithBytesNoCopy: (char *)"" + length: 0 + encoding: NSASCIIStringEncoding + freeWhenDone: NO]; } data_bytes = [d bytes]; if ((data_bytes != NULL) && (len >= 2)) @@ -1668,8 +1672,10 @@ - (id) initWithContentsOfFile: (NSString*)path if (len == 0) { RELEASE(d); - DESTROY(self); - return @""; + return [self initWithBytesNoCopy: (char *)"" + length: 0 + encoding: NSASCIIStringEncoding + freeWhenDone: NO]; } self = [self initWithData: d encoding: enc]; RELEASE(d); @@ -1719,7 +1725,10 @@ - (id) initWithContentsOfURL: (NSURL*)url if (len == 0) { DESTROY(self); - return @""; + return [self initWithBytesNoCopy: (char *)"" + length: 0 + encoding: NSASCIIStringEncoding + freeWhenDone: NO]; } data_bytes = [d bytes]; if ((data_bytes != NULL) && (len >= 2)) @@ -1766,7 +1775,10 @@ - (id) initWithContentsOfURL: (NSURL*)url if (len == 0) { DESTROY(self); - return @""; + return [self initWithBytesNoCopy: (char *)"" + length: 0 + encoding: NSASCIIStringEncoding + freeWhenDone: NO]; } data_bytes = [d bytes]; if ((data_bytes != NULL) && (len >= 2)) @@ -1816,7 +1828,10 @@ - (id) initWithContentsOfURL: (NSURL*)url if (len == 0) { DESTROY(self); - return @""; + return [self initWithBytesNoCopy: (char *)"" + length: 0 + encoding: NSASCIIStringEncoding + freeWhenDone: NO]; } self = [self initWithData: d encoding: enc]; if (self == nil)