ObjFW  Diff

Differences From Artifact [993787fe25]:

To Artifact [85eaead6fd]:


80
81
82
83
84
85
86
87

88
89
90
91
92

93
94
95
96

97
98
99
100
101
102
103

104
105
106
107
108
109
110
111
112
113
114
115
116

117
118
119
120
121
122
123
80
81
82
83
84
85
86

87
88
89
90
91

92
93
94
95

96
97
98
99
100
101
102

103
104
105
106
107
108
109
110
111
112
113
114
115

116
117
118
119
120
121
122
123







-
+




-
+



-
+






-
+












-
+







	return [[[self alloc] initWithBase64EncodedString: string] autorelease];
}

- init
{
	self = [super init];

	itemSize = 1;
	_itemSize = 1;

	return self;
}

- initWithItemSize: (size_t)itemSize_
- initWithItemSize: (size_t)itemSize
{
	self = [super init];

	if (itemSize_ == 0) {
	if (itemSize == 0) {
		Class c = [self class];
		[self release];
		@throw [OFInvalidArgumentException exceptionWithClass: c
							     selector: _cmd];
	}

	itemSize = itemSize_;
	_itemSize = itemSize;

	return self;
}

- initWithContentsOfFile: (OFString*)path
{
	self = [super init];

	@try {
		OFFile *file = [[OFFile alloc] initWithPath: path
						       mode: @"rb"];

		itemSize = 1;
		_itemSize = 1;

		@try {
			size_t pageSize = [OFSystemInfo pageSize];
			char *buffer = [self allocMemoryWithSize: pageSize];

			while (![file isAtEndOfStream]) {
				size_t length;
188
189
190
191
192
193
194
195
196


197
198
199

200
201
202
203

204
205
206

207
208

209
210
211
212
213
214
215
188
189
190
191
192
193
194


195
196
197
198

199
200
201
202

203
204
205

206
207

208
209
210
211
212
213
214
215







-
-
+
+


-
+



-
+


-
+

-
+







{
	self = [super init];

	@try {
		const char *cString;
		size_t i;

		itemSize = 1;
		count = [string
		_itemSize = 1;
		_count = [string
		    cStringLengthWithEncoding: OF_STRING_ENCODING_ASCII];

		if (count & 1)
		if (_count & 1)
			@throw [OFInvalidFormatException
			    exceptionWithClass: [self class]];

		count >>= 1;
		_count >>= 1;
		cString = [string
		    cStringWithEncoding: OF_STRING_ENCODING_ASCII];
		items = [self allocMemoryWithSize: count];
		_items = [self allocMemoryWithSize: _count];

		for (i = 0; i < count; i++) {
		for (i = 0; i < _count; i++) {
			uint8_t c1 = cString[2 * i];
			uint8_t c2 = cString[2 * i + 1];
			uint8_t byte;

			if (c1 >= '0' && c1 <= '9')
				byte = (c1 - '0') << 4;
			else if (c1 >= 'a' && c1 <= 'f')
226
227
228
229
230
231
232
233

234
235
236
237
238
239
240
241
242
243
244
245
246
247
248

249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269

270
271
272
273
274
275
276
226
227
228
229
230
231
232

233
234
235
236
237
238
239
240
241
242
243
244
245
246
247

248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268

269
270
271
272
273
274
275
276







-
+














-
+




















-
+







				byte |= c2 - 'a' + 10;
			else if (c2 >= 'A' && c2 <= 'F')
				byte |= c2 - 'A' + 10;
			else
				@throw [OFInvalidFormatException
				    exceptionWithClass: [self class]];

			items[i] = byte;
			_items[i] = byte;
		}
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- initWithBase64EncodedString: (OFString*)string
{
	self = [super init];

	@try {
		itemSize = 1;
		_itemSize = 1;

		if (!of_base64_decode(self, [string cStringWithEncoding:
		    OF_STRING_ENCODING_ASCII], [string
		    cStringLengthWithEncoding: OF_STRING_ENCODING_ASCII])) {
			Class c = [self class];
			[self release];
			@throw [OFInvalidFormatException exceptionWithClass: c];
		}
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- initWithSerialization: (OFXMLElement*)element
{
	self = [super init];

	itemSize = 1;
	_itemSize = 1;

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFString *stringValue;

		if (![[element name] isEqual: [self className]] ||
		    ![[element namespace] isEqual: OF_SERIALIZATION_NS])
294
295
296
297
298
299
300
301

302
303
304
305
306

307
308
309
310
311

312
313
314
315
316

317
318
319

320
321
322
323
324

325
326
327

328
329
330
331
332

333
334
335

336
337
338
339
340

341
342
343
344
345



346
347

348
349

350
351
352
353
354
355
356
357
358
359
360
361


362
363

364
365
366
367
368



369
370
371


372
373
374

375
376

377
378

379
380
381
382
383



384
385
386
387



388
389

390
391
392
393
394
395
396
397
398
399
400

401
402
403
404
405



406
407

408
409
410
411



412
413
414
415
416
417
418
419

420
421
422

423
424
425
426



427
428
429
430
431
432
433
434

435
436
437


438
439
440
441
442

443
444
445


446
447
448
449
450
451
452

453
454
455
456
457

458
459
460


461
462

463
464
465
466
467
468
469
470

471
472

473
474
475
476
477
478

479
480

481
482
483
484
485
486


487
488
489
490



491
492

493

494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511


512
513
514
515
516
517
518
519
520
521
522
523

524
525
526
527
528
529
530


531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546



547
548
549
550
551
552
553
554

555
556
557
558
559
560
561
562
563
564


565
566
567
568
569
570
571
572
573
574
575

576
577
578
579
580
581
582
583

584
585
586
587
588
589
590
591
592
593
594
595
596

597
598

599
600
601
602

603
604
605
606



607
608

609
610
611


612
613
614
615


616
617

618
619

620
621
622
623

624
625
626
627



628
629

630
631
632


633
634
635

636
637

638
639

640
641
642


643
644
645
646

647
648
649
650



651
652
653
654



655
656
657


658
659
660
661
662

663
664
665

666
667
668
669
670



671
672

673
674

675
676

677
678
679


680
681
682
683
684

685
686
687
688
689
690

691
692

693
694
695

696
697

698
699

700
701
702


703
704
705
706
707

708
709
710
711
712
713
714
715
716
717
718



719
720
721
722
723

724
725
294
295
296
297
298
299
300

301
302
303
304
305

306
307
308
309
310

311
312
313
314
315

316
317
318

319
320
321
322
323

324
325
326

327
328
329
330
331

332
333
334

335
336
337
338
339

340
341
342



343
344
345
346

347
348

349
350
351
352
353
354
355
356
357
358
359


360
361
362

363
364
365



366
367
368
369


370
371
372
373

374
375

376
377

378
379
380



381
382
383
384



385
386
387
388

389
390
391
392
393
394
395
396
397
398
399

400
401
402



403
404
405
406

407
408



409
410
411
412
413
414
415
416
417
418

419
420
421

422
423



424
425
426
427
428
429
430
431
432
433

434
435


436
437
438
439
440
441

442
443


444
445
446
447
448
449
450
451

452
453
454
455
456

457
458


459
460
461

462
463
464
465
466
467
468
469

470
471

472
473
474
475
476
477

478
479

480
481
482
483
484


485
486
487



488
489
490
491

492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510


511
512
513
514
515
516
517
518
519
520
521
522
523

524
525
526
527
528
529


530
531
532
533
534
535
536
537
538
539
540
541
542
543
544



545
546
547
548
549
550
551
552
553
554

555
556
557
558
559
560
561
562
563


564
565
566
567
568
569
570
571
572
573
574
575

576
577
578
579
580
581
582
583

584
585
586
587
588
589
590
591
592
593
594
595
596

597
598

599
600
601
602

603
604



605
606
607
608

609
610


611
612
613
614


615
616
617

618
619

620
621
622
623

624
625



626
627
628
629

630
631


632
633
634
635

636
637

638
639

640
641


642
643
644
645
646

647
648



649
650
651
652



653
654
655
656


657
658
659
660
661
662

663
664
665

666
667
668



669
670
671
672

673
674

675
676

677
678


679
680
681
682
683
684

685
686
687
688
689
690

691
692

693
694
695

696
697

698
699

700
701


702
703
704
705
706
707

708
709
710
711
712
713
714
715
716



717
718
719
720
721
722
723

724
725
726







-
+




-
+




-
+




-
+


-
+




-
+


-
+




-
+


-
+




-
+


-
-
-
+
+
+

-
+

-
+










-
-
+
+

-
+


-
-
-
+
+
+

-
-
+
+


-
+

-
+

-
+


-
-
-
+
+
+

-
-
-
+
+
+

-
+










-
+


-
-
-
+
+
+

-
+

-
-
-
+
+
+







-
+


-
+

-
-
-
+
+
+







-
+

-
-
+
+




-
+

-
-
+
+






-
+




-
+

-
-
+
+

-
+







-
+

-
+





-
+

-
+




-
-
+
+

-
-
-
+
+
+

-
+

+
















-
-
+
+











-
+





-
-
+
+













-
-
-
+
+
+







-
+








-
-
+
+










-
+







-
+












-
+

-
+



-
+

-
-
-
+
+
+

-
+

-
-
+
+


-
-
+
+

-
+

-
+



-
+

-
-
-
+
+
+

-
+

-
-
+
+


-
+

-
+

-
+

-
-
+
+



-
+

-
-
-
+
+
+

-
-
-
+
+
+

-
-
+
+




-
+


-
+


-
-
-
+
+
+

-
+

-
+

-
+

-
-
+
+




-
+





-
+

-
+


-
+

-
+

-
+

-
-
+
+




-
+








-
-
-
+
+
+




-
+


	}

	return self;
}

- (size_t)count
{
	return count;
	return _count;
}

- (size_t)itemSize
{
	return itemSize;
	return _itemSize;
}

- (void*)items
{
	return items;
	return _items;
}

- (void*)itemAtIndex: (size_t)index
{
	if (index >= count)
	if (index >= _count)
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];

	return items + index * itemSize;
	return _items + index * _itemSize;
}

- (void*)firstItem
{
	if (items == NULL || count == 0)
	if (_items == NULL || _count == 0)
		return NULL;

	return items;
	return _items;
}

- (void*)lastItem
{
	if (items == NULL || count == 0)
	if (_items == NULL || _count == 0)
		return NULL;

	return items + (count - 1) * itemSize;
	return _items + (_count - 1) * _itemSize;
}

- (void)addItem: (const void*)item
{
	if (SIZE_MAX - count < 1)
	if (SIZE_MAX - _count < 1)
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];

	items = [self resizeMemory: items
			      size: itemSize
			     count: count + 1];
	_items = [self resizeMemory: _items
			       size: _itemSize
			      count: _count + 1];

	memcpy(items + count * itemSize, item, itemSize);
	memcpy(_items + _count * _itemSize, item, _itemSize);

	count++;
	_count++;
}

- (void)insertItem: (const void*)item
	   atIndex: (size_t)index
{
	[self insertItems: item
		  atIndex: index
		    count: 1];
}

- (void)addItems: (const void*)items_
	   count: (size_t)count_
- (void)addItems: (const void*)items
	   count: (size_t)count
{
	if (count_ > SIZE_MAX - count)
	if (count > SIZE_MAX - count)
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];

	items = [self resizeMemory: items
			      size: itemSize
			     count: count + count_];
	_items = [self resizeMemory: _items
			       size: _itemSize
			      count: _count + count];

	memcpy(items + count * itemSize, items_, count_ * itemSize);
	count += count_;
	memcpy(_items + _count * _itemSize, items, count * _itemSize);
	_count += count;
}

- (void)insertItems: (const void*)items_
- (void)insertItems: (const void*)items
	    atIndex: (size_t)index
	      count: (size_t)count_
	      count: (size_t)count
{
	if (count_ > SIZE_MAX - count || index > count)
	if (count > SIZE_MAX - _count || index > _count)
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];

	items = [self resizeMemory: items
			      size: itemSize
			     count: count + count_];
	_items = [self resizeMemory: _items
			       size: _itemSize
			      count: _count + count];

	memmove(items + (index + count_) * itemSize, items + index * itemSize,
	    (count - index) * itemSize);
	memcpy(items + index * itemSize, items_, count_ * itemSize);
	memmove(_items + (index + count) * _itemSize,
	    _items + index * _itemSize, (_count - index) * _itemSize);
	memcpy(_items + index * _itemSize, items, count * _itemSize);

	count += count_;
	_count += count;
}

- (void)removeItemAtIndex: (size_t)index
{
	[self removeItemsInRange: of_range(index, 1)];
}

- (void)removeItemsInRange: (of_range_t)range
{
	if (range.length > SIZE_MAX - range.location ||
	    range.location + range.length > count)
	    range.location + range.length > _count)
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];

	memmove(items + range.location * itemSize,
	    items + (range.location + range.length) * itemSize,
	    (count - range.location - range.length) * itemSize);
	memmove(_items + range.location * _itemSize,
	    _items + (range.location + range.length) * _itemSize,
	    (_count - range.location - range.length) * _itemSize);

	count -= range.length;
	_count -= range.length;
	@try {
		items = [self resizeMemory: items
				      size: itemSize
				     count: count];
		_items = [self resizeMemory: _items
				       size: _itemSize
				      count: _count];
	} @catch (OFOutOfMemoryException *e) {
		/* We don't really care, as we only made it smaller */
	}
}

- (void)removeLastItem
{
	if (count == 0)
	if (_count == 0)
		return;

	count--;
	_count--;
	@try {
		items = [self resizeMemory: items
				      size: itemSize
				     count: count];
		_items = [self resizeMemory: _items
				       size: _itemSize
				      count: _count];
	} @catch (OFOutOfMemoryException *e) {
		/* We don't care, as we only made it smaller */
	}
}

- (void)removeAllItems
{
	[self freeMemory: items];
	[self freeMemory: _items];

	items = NULL;
	count = 0;
	_items = NULL;
	_count = 0;
}

- copy
{
	OFDataArray *copy = [[[self class] alloc] initWithItemSize: itemSize];
	OFDataArray *copy = [[[self class] alloc] initWithItemSize: _itemSize];

	[copy addItems: items
		 count: count];
	[copy addItems: _items
		 count: _count];

	return copy;
}

- (BOOL)isEqual: (id)object
{
	OFDataArray *otherDataArray;
	OFDataArray *dataArray;

	if (![object isKindOfClass: [OFDataArray class]])
		return NO;

	otherDataArray = object;
	dataArray = object;

	if ([otherDataArray count] != count ||
	    [otherDataArray itemSize] != itemSize)
	if ([dataArray count] != _count ||
	    [dataArray itemSize] != _itemSize)
		return NO;
	if (memcmp([otherDataArray items], items, count * itemSize))
	if (memcmp([dataArray items], _items, _count * _itemSize))
		return NO;

	return YES;
}

- (of_comparison_result_t)compare: (id <OFComparing>)object
{
	OFDataArray *otherDataArray;
	OFDataArray *dataArray;
	int comparison;
	size_t otherCount, minimumCount;
	size_t count, minCount;

	if (![object isKindOfClass: [OFDataArray class]])
		@throw [OFInvalidArgumentException
		    exceptionWithClass: [self class]
			      selector: _cmd];
	otherDataArray = (OFDataArray*)object;
	dataArray = (OFDataArray*)object;

	if ([otherDataArray itemSize] != itemSize)
	if ([dataArray itemSize] != _itemSize)
		@throw [OFInvalidArgumentException
		    exceptionWithClass: [self class]
			      selector: _cmd];

	otherCount = [otherDataArray count];
	minimumCount = (count > otherCount ? otherCount : count);
	count = [dataArray count];
	minCount = (_count > count ? count : _count);

	if ((comparison = memcmp(items, [otherDataArray items],
	    minimumCount * itemSize)) == 0) {
		if (count > otherCount)
	if ((comparison = memcmp(_items, [dataArray items],
	    minCount * _itemSize)) == 0) {
		if (_count > count)
			return OF_ORDERED_DESCENDING;
		if (count < otherCount)
		if (_count < count)
			return OF_ORDERED_ASCENDING;

		return OF_ORDERED_SAME;
	}

	if (comparison > 0)
		return OF_ORDERED_DESCENDING;
	else
		return OF_ORDERED_ASCENDING;
}

- (uint32_t)hash
{
	uint32_t hash;
	size_t i;

	OF_HASH_INIT(hash);

	for (i = 0; i < count * itemSize; i++)
		OF_HASH_ADD(hash, ((uint8_t*)items)[i]);
	for (i = 0; i < _count * _itemSize; i++)
		OF_HASH_ADD(hash, ((uint8_t*)_items)[i]);

	OF_HASH_FINALIZE(hash);

	return hash;
}

- (OFString*)description
{
	OFMutableString *ret = [OFMutableString stringWithString: @"<"];
	size_t i;

	for (i = 0; i < count; i++) {
	for (i = 0; i < _count; i++) {
		size_t j;

		if (i > 0)
			[ret appendString: @" "];

		for (j = 0; j < itemSize; j++)
			[ret appendFormat: @"%02x", items[i * itemSize + j]];
		for (j = 0; j < _itemSize; j++)
			[ret appendFormat: @"%02x", _items[i * _itemSize + j]];
	}

	[ret appendString: @">"];

	[ret makeImmutable];
	return ret;
}

- (OFString*)stringRepresentation
{
	OFMutableString *ret = [OFMutableString string];
	size_t i, j;

	for (i = 0; i < count; i++)
		for (j = 0; j < itemSize; j++)
			[ret appendFormat: @"%02x", items[i * itemSize + j]];
	for (i = 0; i < _count; i++)
		for (j = 0; j < _itemSize; j++)
			[ret appendFormat: @"%02x", _items[i * _itemSize + j]];

	[ret makeImmutable];
	return ret;
}

- (OFString*)stringByBase64Encoding
{
	return of_base64_encode(items, count * itemSize);
	return of_base64_encode(_items, _count * _itemSize);
}

- (void)writeToFile: (OFString*)path
{
	OFFile *file = [[OFFile alloc] initWithPath: path
					       mode: @"wb"];

	@try {
		[file writeBuffer: items
			   length: count * itemSize];
		[file writeBuffer: _items
			   length: _count * _itemSize];
	} @finally {
		[file release];
	}
}

- (OFXMLElement*)XMLElementBySerializing
{
	void *pool;
	OFXMLElement *element;

	if (itemSize != 1)
	if (_itemSize != 1)
		@throw [OFInvalidArgumentException
		    exceptionWithClass: [self class]];

	pool = objc_autoreleasePoolPush();
	element = [OFXMLElement
	    elementWithName: [self className]
		  namespace: OF_SERIALIZATION_NS
		stringValue: of_base64_encode(items, count * itemSize)];
		stringValue: of_base64_encode(_items, _count * _itemSize)];

	[element retain];

	objc_autoreleasePoolPop(pool);

	return [element autorelease];
}
@end

@implementation OFBigDataArray
- (void)addItem: (const void*)item
{
	size_t newSize, lastPageByte;
	size_t size, lastPageByte;

	if (SIZE_MAX - count < 1 || count + 1 > SIZE_MAX / itemSize)
	if (SIZE_MAX - _count < 1 || _count + 1 > SIZE_MAX / _itemSize)
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];

	lastPageByte = [OFSystemInfo pageSize] - 1;
	newSize = ((count + 1) * itemSize + lastPageByte) & ~lastPageByte;
	size = ((_count + 1) * _itemSize + lastPageByte) & ~lastPageByte;

	if (size != newSize)
		items = [self resizeMemory: items
				      size: newSize];
	if (_size != size)
		_items = [self resizeMemory: _items
				       size: size];

	memcpy(items + count * itemSize, item, itemSize);
	memcpy(_items + _count * _itemSize, item, _itemSize);

	count++;
	size = newSize;
	_count++;
	_size = size;
}

- (void)addItems: (const void*)items_
	   count: (size_t)count_
- (void)addItems: (const void*)items
	   count: (size_t)count
{
	size_t newSize, lastPageByte;
	size_t size, lastPageByte;

	if (count_ > SIZE_MAX - count || count + count_ > SIZE_MAX / itemSize)
	if (count > SIZE_MAX - _count || _count + count > SIZE_MAX / _itemSize)
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];

	lastPageByte = [OFSystemInfo pageSize] - 1;
	newSize = ((count + count_) * itemSize + lastPageByte) & ~lastPageByte;
	size = ((_count + count) * _itemSize + lastPageByte) & ~lastPageByte;

	if (size != newSize)
		items = [self resizeMemory: items
				      size: newSize];
	if (_size != size)
		_items = [self resizeMemory: _items
				       size: size];

	memcpy(items + count * itemSize, items_, count_ * itemSize);
	memcpy(_items + _count * _itemSize, items, count * _itemSize);

	count += count_;
	size = newSize;
	_count += count;
	_size = size;
}

- (void)insertItems: (const void*)items_
- (void)insertItems: (const void*)items
	    atIndex: (size_t)index
	      count: (size_t)count_
	      count: (size_t)count
{
	size_t newSize, lastPageByte;
	size_t size, lastPageByte;

	if (count_ > SIZE_MAX - count || index > count ||
	    count + count_ > SIZE_MAX / itemSize)
	if (count > SIZE_MAX - _count || index > _count ||
	    _count + count > SIZE_MAX / _itemSize)
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];

	lastPageByte = [OFSystemInfo pageSize] - 1;
	newSize = ((count + count_) * itemSize + lastPageByte) & ~lastPageByte;
	size = ((_count + count) * _itemSize + lastPageByte) & ~lastPageByte;

	if (size != newSize)
		items = [self resizeMemory: items
				      size: newSize];
	if (_size != size)
		_items = [self resizeMemory: _items
				       size: size];

	memmove(items + (index + count_) * itemSize, items + index * itemSize,
	    (count - index) * itemSize);
	memcpy(items + index * itemSize, items_, count_ * itemSize);
	memmove(_items + (index + count) * _itemSize,
	    _items + index * _itemSize, (_count - index) * _itemSize);
	memcpy(_items + index * _itemSize, items, count * _itemSize);

	count += count_;
	size = newSize;
	_count += count;
	_size = size;
}

- (void)removeItemsInRange: (of_range_t)range
{
	size_t pageSize, newSize;
	size_t pageSize, size;

	if (range.length > SIZE_MAX - range.location ||
	    range.location + range.length > count)
	    range.location + range.length > _count)
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];

	memmove(items + range.location * itemSize,
	    items + (range.location + range.length) * itemSize,
	    (count - range.location - range.length) * itemSize);
	memmove(_items + range.location * _itemSize,
	    _items + (range.location + range.length) * _itemSize,
	    (_count - range.location - range.length) * _itemSize);

	count -= range.length;
	_count -= range.length;
	pageSize = [OFSystemInfo pageSize];
	newSize = (count * itemSize + pageSize - 1) & ~(pageSize - 1);
	size = (_count * _itemSize + pageSize - 1) & ~(pageSize - 1);

	if (size != newSize && newSize >= pageSize) {
	if (_size != size && size >= pageSize) {
		@try {
			items = [self resizeMemory: items
					      size: newSize];
			_items = [self resizeMemory: _items
					       size: size];
		} @catch (OFOutOfMemoryException *e) {
			/* We don't care, as we only made it smaller */
		}

		size = newSize;
		_size = size;
	}
}

- (void)removeLastItem
{
	size_t pageSize, newSize;
	size_t pageSize, size;

	if (count == 0)
	if (_count == 0)
		return;

	count--;
	_count--;
	pageSize = [OFSystemInfo pageSize];
	newSize = (count * itemSize + pageSize - 1) & ~(pageSize - 1);
	size = (_count * _itemSize + pageSize - 1) & ~(pageSize - 1);

	if (size != newSize && newSize >= pageSize) {
	if (_size != size && size >= pageSize) {
		@try {
			items = [self resizeMemory: items
					      size: newSize];
			_items = [self resizeMemory: _items
					       size: size];
		} @catch (OFOutOfMemoryException *e) {
			/* We don't care, as we only made it smaller */
		}

		size = newSize;
		_size = size;
	}
}

- (void)removeAllItems
{
	size_t pageSize = [OFSystemInfo pageSize];

	@try {
		items = [self resizeMemory: items
				      size: pageSize];
		size = pageSize;
		_items = [self resizeMemory: _items
				       size: pageSize];
		_size = pageSize;
	} @catch (OFOutOfMemoryException *e) {
		/* We don't care, as we only made it smaller */
	}

	count = 0;
	_count = 0;
}
@end