ObjFW  Diff

Differences From Artifact [8775708778]:

To Artifact [bb1c57067e]:


159
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186






187
188
189
190
191
192
193
159
160
161
162
163
164
165

166

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183


184
185
186
187
188
189
190
191
192
193
194
195
196







-
+
-

















-
-
+
+
+
+
+
+







		if (capacity * 8 / _capacity >= 6)
			if (_capacity <= ULONG_MAX / 2)
				_capacity *= 2;

		if (_capacity < MIN_CAPACITY)
			_capacity = MIN_CAPACITY;

		_buckets = [self allocZeroedMemoryWithSize: sizeof(*_buckets)
		_buckets = of_calloc(_capacity, sizeof(*_buckets));
						     count: _capacity];

		if (of_hash_seed != 0)
			_rotate = of_random16() & 31;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	for (unsigned long i = 0; i < _capacity; i++) {
		if (_buckets[i] != NULL && _buckets[i] != &deleted) {
			_keyFunctions.release(_buckets[i]->key);
			_objectFunctions.release(_buckets[i]->object);
		}
	}

			free(_buckets[i]);
		}
	}

	free(_buckets);

	[super dealloc];
}

- (bool)isEqual: (id)object
{
	OFMapTable *mapTable;
318
319
320
321
322
323
324
325

326
327
328
329
330
331
332
333
321
322
323
324
325
326
327

328

329
330
331
332
333
334
335







-
+
-







	/*
	 * Don't downsize if we have an initial capacity or if we would fall
	 * below the minimum capacity.
	 */
	if ((capacity < _capacity && count > _count) || capacity < MIN_CAPACITY)
		return;

	buckets = [self allocZeroedMemoryWithSize: sizeof(*buckets)
	buckets = of_calloc(capacity, sizeof(*buckets));
					    count: capacity];

	for (unsigned long i = 0; i < _capacity; i++) {
		if (_buckets[i] != NULL && _buckets[i] != &deleted) {
			unsigned long j, last;

			last = capacity;

345
346
347
348
349
350
351
352

353
354
355
356
357
358
359
347
348
349
350
351
352
353

354
355
356
357
358
359
360
361







-
+







			if (j >= last)
				@throw [OFOutOfRangeException exception];

			buckets[j] = _buckets[i];
		}
	}

	[self freeMemory: _buckets];
	free(_buckets);
	_buckets = buckets;
	_capacity = capacity;
}

- (void)of_setObject: (void *)object
	      forKey: (void *)key
		hash: (unsigned long)hash
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
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







-
+




-
+







-
+







			for (i = 0; i < last && _buckets[i] != NULL &&
			    _buckets[i] != &deleted; i++);
		}

		if (i >= last)
			@throw [OFOutOfRangeException exception];

		bucket = [self allocMemoryWithSize: sizeof(*bucket)];
		bucket = of_malloc(1, sizeof(*bucket));

		@try {
			bucket->key = _keyFunctions.retain(key);
		} @catch (id e) {
			[self freeMemory: bucket];
			free(bucket);
			@throw e;
		}

		@try {
			bucket->object = _objectFunctions.retain(object);
		} @catch (id e) {
			_keyFunctions.release(bucket->key);
			[self freeMemory: bucket];
			free(bucket);
			@throw e;
		}

		bucket->hash = hash;

		_buckets[i] = bucket;
		_count++;
466
467
468
469
470
471
472
473

474
475
476
477
478
479
480
468
469
470
471
472
473
474

475
476
477
478
479
480
481
482







-
+








		if (_keyFunctions.equal(_buckets[i]->key, key)) {
			_mutations++;

			_keyFunctions.release(_buckets[i]->key);
			_objectFunctions.release(_buckets[i]->object);

			[self freeMemory: _buckets[i]];
			free(_buckets[i]);
			_buckets[i] = &deleted;

			_count--;
			[self of_resizeForCount: _count];

			return;
		}
490
491
492
493
494
495
496
497

498
499
500
501
502
503
504
492
493
494
495
496
497
498

499
500
501
502
503
504
505
506







-
+







		if (_buckets[i] == &deleted)
			continue;

		if (_keyFunctions.equal(_buckets[i]->key, key)) {
			_keyFunctions.release(_buckets[i]->key);
			_objectFunctions.release(_buckets[i]->object);

			[self freeMemory: _buckets[i]];
			free(_buckets[i]);
			_buckets[i] = &deleted;

			_count--;
			_mutations++;
			[self of_resizeForCount: _count];

			return;
514
515
516
517
518
519
520
521

522
523
524
525
526
527
528
529

530
531
532
533
534
535
536
537
516
517
518
519
520
521
522

523
524
525
526
527
528
529


530

531
532
533
534
535
536
537







-
+






-
-
+
-







				_buckets[i] = NULL;
				continue;
			}

			_keyFunctions.release(_buckets[i]->key);
			_objectFunctions.release(_buckets[i]->object);

			[self freeMemory: _buckets[i]];
			free(_buckets[i]);
			_buckets[i] = NULL;
		}
	}

	_count = 0;
	_capacity = MIN_CAPACITY;
	_buckets = [self resizeMemory: _buckets
				 size: sizeof(*_buckets)
	_buckets = of_realloc(_buckets, _capacity, sizeof(*_buckets));
				count: _capacity];

	/*
	 * Get a new random value for _rotate, so that it is not less secure
	 * than creating a new hash map.
	 */
	if (of_hash_seed != 0)
		_rotate = of_random16() & 31;