From 2758b44d3775fdbda9ecfb8214443779a567f29d Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Sat, 6 Oct 2012 14:19:34 -0400 Subject: [PATCH] Small optimization, we avoid copying potentially big array of bytes by attaching a wrapper around the NSData object to the resulting binary structure --- OpenChange/NSData+MAPIStore.m | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/OpenChange/NSData+MAPIStore.m b/OpenChange/NSData+MAPIStore.m index b1200c5f4..b2bdedc97 100644 --- a/OpenChange/NSData+MAPIStore.m +++ b/OpenChange/NSData+MAPIStore.m @@ -22,6 +22,7 @@ #import +#import "NSObject+MAPIStore.h" #import "NSString+MAPIStore.h" #import "NSData+MAPIStore.h" @@ -42,13 +43,11 @@ - (struct Binary_r *) asBinaryInMemCtx: (void *) memCtx { struct Binary_r *binary; - uint8_t *lpb; binary = talloc_zero (memCtx, struct Binary_r); binary->cb = [self length]; - lpb = talloc_array (binary, uint8_t, binary->cb); - [self getBytes: lpb]; - binary->lpb = lpb; + binary->lpb = (uint8_t *) [self bytes]; + [self tallocWrapper: binary]; return binary; } @@ -61,13 +60,11 @@ - (struct SBinary_short *) asShortBinaryInMemCtx: (void *) memCtx { struct SBinary_short *binary; - uint8_t *lpb; binary = talloc_zero (memCtx, struct SBinary_short); binary->cb = [self length]; - lpb = talloc_array (binary, uint8_t, binary->cb); - [self getBytes: lpb]; - binary->lpb = lpb; + binary->lpb = (uint8_t *) [self bytes]; + [self tallocWrapper: binary]; return binary; }