cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject ios commit: Use noCopy versions of NSString init in Base64 code.
Date Fri, 15 Mar 2013 20:45:25 GMT
Updated Branches:
  refs/heads/master 8e4a7aefd -> 52702d87c


Use noCopy versions of NSString init in Base64 code.


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/52702d87
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/52702d87
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/52702d87

Branch: refs/heads/master
Commit: 52702d87c935a7dd8f840d8f795ae37df43de631
Parents: 8e4a7ae
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Mon Mar 11 22:02:00 2013 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Fri Mar 15 16:44:07 2013 -0400

----------------------------------------------------------------------
 CordovaLib/Classes/NSData+Base64.m |   19 +++++++------------
 1 files changed, 7 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/52702d87/CordovaLib/Classes/NSData+Base64.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/NSData+Base64.m b/CordovaLib/Classes/NSData+Base64.m
index 08c801b..d0f2189 100644
--- a/CordovaLib/Classes/NSData+Base64.m
+++ b/CordovaLib/Classes/NSData+Base64.m
@@ -249,13 +249,10 @@ char *CDVNewBase64Encode(
 //
 + (NSData*)dataFromBase64String:(NSString*)aString
 {
-    NSData* data = [aString dataUsingEncoding:NSASCIIStringEncoding];
-    size_t outputLength;
-    void* outputBuffer = CDVNewBase64Decode([data bytes], [data length], &outputLength);
-    NSData* result = [NSData dataWithBytes:outputBuffer length:outputLength];
+    size_t outputLength = 0;
+    void* outputBuffer = CDVNewBase64Decode([aString UTF8String], [aString length], &outputLength);
 
-    free(outputBuffer);
-    return result;
+    return [NSData dataWithBytesNoCopy:outputBuffer length:outputLength freeWhenDone:YES];
 }
 
 //
@@ -273,13 +270,11 @@ char *CDVNewBase64Encode(
     char* outputBuffer =
         CDVNewBase64Encode([self bytes], [self length], true, &outputLength);
 
-    NSString* result =
-        [[NSString alloc]
-        initWithBytes:outputBuffer
-               length:outputLength
-             encoding:NSASCIIStringEncoding];
+    NSString* result = [[NSString alloc] initWithBytesNoCopy:outputBuffer
+                                                      length:outputLength
+                                                    encoding:NSASCIIStringEncoding
+                                                freeWhenDone:YES];
 
-    free(outputBuffer);
     return result;
 }
 


Mime
View raw message