@@ -1,7 +1,7 @@ /* - * Copyright (c) 2008-2022 Jonathan Schleifer + * Copyright (c) 2008-2024 Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in @@ -338,12 +338,11 @@ itemSize: itemSize allowsSwappableMemory: allowsSwappableMemory] autorelease]; } -+ (instancetype)dataWithItems: (const void *)items - count: (size_t)count ++ (instancetype)dataWithItems: (const void *)items count: (size_t)count { OF_UNRECOGNIZED_SELECTOR } + (instancetype)dataWithItems: (const void *)items @@ -373,11 +372,11 @@ { OF_UNRECOGNIZED_SELECTOR } #endif -+ (instancetype)dataWithContentsOfURI: (OFURI *)URI ++ (instancetype)dataWithContentsOfIRI: (OFIRI *)IRI { OF_UNRECOGNIZED_SELECTOR } + (instancetype)dataWithStringRepresentation: (OFString *)string @@ -387,11 +386,10 @@ + (instancetype)dataWithBase64EncodedString: (OFString *)string { OF_UNRECOGNIZED_SELECTOR } - - (instancetype)initWithCount: (size_t)count allowsSwappableMemory: (bool)allowsSwappableMemory { return [self initWithCount: count @@ -462,10 +460,20 @@ @throw e; } return self; } + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithItemSize: (size_t)itemSize +{ + OF_INVALID_INIT_METHOD +} - (instancetype)initWithItems: (const void *)items count: (size_t)count { OF_INVALID_INIT_METHOD } @@ -497,11 +505,11 @@ { OF_INVALID_INIT_METHOD } #endif -- (instancetype)initWithContentsOfURI: (OFURI *)URI +- (instancetype)initWithContentsOfIRI: (OFIRI *)IRI { OF_INVALID_INIT_METHOD } - (instancetype)initWithStringRepresentation: (OFString *)string @@ -509,15 +517,10 @@ OF_INVALID_INIT_METHOD } - (instancetype)initWithBase64EncodedString: (OFString *)string { - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithSerialization: (OFXMLElement *)element -{ OF_INVALID_INIT_METHOD } - (void)dealloc { @@ -538,12 +541,30 @@ removePageIfEmpty(_page); } } #endif + if (_freeWhenDone) + OFFreeMemory(_items); + [super dealloc]; } + +- (size_t)count +{ + return _count; +} + +- (size_t)itemSize +{ + return _itemSize; +} + +- (const void *)items +{ + return _items; +} - (void *)mutableItems { return _items; } @@ -586,27 +607,29 @@ } - (bool)isEqual: (id)object { OFData *otherData; + const unsigned char *otherDataItems; unsigned char diff; if (object == self) return true; if (![object isKindOfClass: [OFData class]]) return false; otherData = object; + otherDataItems = otherData.items; - if (otherData->_count != _count || otherData->_itemSize != _itemSize) + if (otherData.count != _count || otherData.itemSize != _itemSize) return false; diff = 0; for (size_t i = 0; i < _count * _itemSize; i++) - diff |= otherData->_items[i] ^ _items[i]; + diff |= otherDataItems[i] ^ _items[i]; return (diff == 0); } - (OFString *)description @@ -629,20 +652,15 @@ { OF_UNRECOGNIZED_SELECTOR } #endif -- (void)writeToURI: (OFURI *)URI -{ - OF_UNRECOGNIZED_SELECTOR -} - -- (OFXMLElement *)XMLElementBySerializing +- (void)writeToIRI: (OFIRI *)IRI { OF_UNRECOGNIZED_SELECTOR } - (OFData *)messagePackRepresentation { OF_UNRECOGNIZED_SELECTOR } @end