Skip to content

Commit

Permalink
fix small bug and add optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
rfm committed Feb 2, 2024
1 parent 947f0f8 commit d6bb6de
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2024-02-02 Richard Frith-Macdonald <[email protected]>

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 <[email protected]>

* Source/NSLocale.m: Fix -countryCode incorrectly returning language
Expand Down
6 changes: 3 additions & 3 deletions Source/Additions/GSMime.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -8085,7 +8085,7 @@ - (void) encodePart: (GSMimeDocument*)document to: (NSMutableData*)md
[document setHeader: @"Content-Transfer-Encoding"
value: enc
parameters: nil];
}
}
}
}

Expand Down
33 changes: 24 additions & 9 deletions Source/NSString.m
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d6bb6de

Please sign in to comment.