Index: src/OFData.h ================================================================== --- src/OFData.h +++ src/OFData.h @@ -112,11 +112,11 @@ * @param count The number of items * @param freeWhenDone Whether to free the pointer when it is no longer needed * by the OFData * @return A new autoreleased OFData */ -+ (instancetype)dataWithItemsNoCopy: (const void *)items ++ (instancetype)dataWithItemsNoCopy: (void *)items count: (size_t)count freeWhenDone: (bool)freeWhenDone; /*! * @brief Creates a new OFData with the specified `count` items of the @@ -127,11 +127,11 @@ * @param count The number of items * @param freeWhenDone Whether to free the pointer when it is no longer needed * by the OFData * @return A new autoreleased OFData */ -+ (instancetype)dataWithItemsNoCopy: (const void *)items ++ (instancetype)dataWithItemsNoCopy: (void *)items itemSize: (size_t)itemSize count: (size_t)count freeWhenDone: (bool)freeWhenDone; #ifdef OF_HAVE_FILES @@ -209,11 +209,11 @@ * @param count The number of items * @param freeWhenDone Whether to free the pointer when it is no longer needed * by the OFData * @return An initialized OFData */ -- (instancetype)initWithItemsNoCopy: (const void *)items +- (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count freeWhenDone: (bool)freeWhenDone; /*! * @brief Initializes an already allocated OFData with the specified `count` @@ -225,11 +225,11 @@ * @param count The number of items * @param freeWhenDone Whether to free the pointer when it is no longer needed * by the OFData * @return An initialized OFData */ -- (instancetype)initWithItemsNoCopy: (const void *)items +- (instancetype)initWithItemsNoCopy: (void *)items itemSize: (size_t)itemSize count: (size_t)count freeWhenDone: (bool)freeWhenDone; #ifdef OF_HAVE_FILES Index: src/OFData.m ================================================================== --- src/OFData.m +++ src/OFData.m @@ -67,20 +67,20 @@ return [[[self alloc] initWithItems: items itemSize: itemSize count: count] autorelease]; } -+ (instancetype)dataWithItemsNoCopy: (const void *)items ++ (instancetype)dataWithItemsNoCopy: (void *)items count: (size_t)count freeWhenDone: (bool)freeWhenDone { return [[[self alloc] initWithItemsNoCopy: items count: count freeWhenDone: freeWhenDone] autorelease]; } -+ (instancetype)dataWithItemsNoCopy: (const void *)items ++ (instancetype)dataWithItemsNoCopy: (void *)items itemSize: (size_t)itemSize count: (size_t)count freeWhenDone: (bool)freeWhenDone { return [[[self alloc] initWithItemsNoCopy: items @@ -154,21 +154,21 @@ } return self; } -- (instancetype)initWithItemsNoCopy: (const void *)items +- (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count freeWhenDone: (bool)freeWhenDone { return [self initWithItemsNoCopy: items itemSize: 1 count: count freeWhenDone: freeWhenDone]; } -- (instancetype)initWithItemsNoCopy: (const void *)items +- (instancetype)initWithItemsNoCopy: (void *)items itemSize: (size_t)itemSize count: (size_t)count freeWhenDone: (bool)freeWhenDone { self = [super init]; Index: src/OFMutableData.h ================================================================== --- src/OFMutableData.h +++ src/OFMutableData.h @@ -65,18 +65,10 @@ * @return A new autoreleased OFMutableData */ + (instancetype)dataWithItemSize: (size_t)itemSize capacity: (size_t)capacity; -+ (instancetype)dataWithItemsNoCopy: (const void *)items - count: (size_t)count - freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE; -+ (instancetype)dataWithItemsNoCopy: (const void *)items - itemSize: (size_t)itemSize - count: (size_t)count - freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE; - /*! * @brief Initializes an already allocated OFMutableData with an item size of 1. * * @return An initialized OFMutableData */ @@ -111,18 +103,10 @@ * @return An initialized OFMutableData */ - (instancetype)initWithItemSize: (size_t)itemSize capacity: (size_t)capacity; -- (instancetype)initWithItemsNoCopy: (const void *)items - count: (size_t)count - freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE; -- (instancetype)initWithItemsNoCopy: (const void *)items - itemSize: (size_t)itemSize - count: (size_t)count - freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE; - /*! * @brief Adds an item to the OFMutableData. * * @param item A pointer to an arbitrary item */ Index: src/OFMutableData.m ================================================================== --- src/OFMutableData.m +++ src/OFMutableData.m @@ -49,25 +49,10 @@ { return [[[self alloc] initWithItemSize: itemSize capacity: capacity] autorelease]; } -+ (instancetype)dataWithItemsNoCopy: (const void *)items - count: (size_t)count - freeWhenDone: (bool)freeWhenDone -{ - OF_UNRECOGNIZED_SELECTOR -} - -+ (instancetype)dataWithItemsNoCopy: (const void *)items - itemSize: (size_t)itemSize - count: (size_t)count - freeWhenDone: (bool)freeWhenDone -{ - OF_UNRECOGNIZED_SELECTOR -} - - (instancetype)init { self = [super of_init]; _itemSize = 1; @@ -131,23 +116,36 @@ _capacity = _count; return self; } -- (instancetype)initWithItemsNoCopy: (const void *)items +- (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count freeWhenDone: (bool)freeWhenDone { - OF_INVALID_INIT_METHOD + self = [self initWithItems: items + count: count]; + + if (freeWhenDone) + free(items); + + return self; } -- (instancetype)initWithItemsNoCopy: (const void *)items +- (instancetype)initWithItemsNoCopy: (void *)items itemSize: (size_t)itemSize count: (size_t)count freeWhenDone: (bool)freeWhenDone { - OF_INVALID_INIT_METHOD + self = [self initWithItems: items + itemSize: itemSize + count: count]; + + if (freeWhenDone) + free(items); + + return self; } - (instancetype)initWithStringRepresentation: (OFString *)string { self = [super initWithStringRepresentation: string];