ObjFW  Diff

Differences From Artifact [b21568683c]:

To Artifact [c4df3481c5]:


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{
	if (self == [OFMutableDictionary_hashtable class]) {
		dictionary = [OFDictionary_hashtable class];
		[self inheritMethodsFromClass: dictionary];
	}
}

- (void)_resizeForCount: (size_t)newCount
{
	size_t fullness = newCount * 4 / size;
	struct of_dictionary_hashtable_bucket **newData;
	uint32_t i, newSize;

	if (newCount > UINT32_MAX)
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];







|







36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{
	if (self == [OFMutableDictionary_hashtable class]) {
		dictionary = [OFDictionary_hashtable class];
		[self inheritMethodsFromClass: dictionary];
	}
}

- (void)OF_resizeForCount: (size_t)newCount
{
	size_t fullness = newCount * 4 / size;
	struct of_dictionary_hashtable_bucket **newData;
	uint32_t i, newSize;

	if (newCount > UINT32_MAX)
		@throw [OFOutOfRangeException exceptionWithClass: [self class]];
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
	}

	[self freeMemory: data];
	data = newData;
	size = newSize;
}

- (void)_setObject: (id)object
	    forKey: (id)key
	   copyKey: (BOOL)copyKey
{
	uint32_t i, hash, last;
	id old;

	if (key == nil || object == nil)
		@throw [OFInvalidArgumentException
		    exceptionWithClass: [self class]







|
|
|







93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
	}

	[self freeMemory: data];
	data = newData;
	size = newSize;
}

- (void)OF_setObject: (id)object
	      forKey: (id)key
	     copyKey: (BOOL)copyKey
{
	uint32_t i, hash, last;
	id old;

	if (key == nil || object == nil)
		@throw [OFInvalidArgumentException
		    exceptionWithClass: [self class]
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
	}

	/* Key not in dictionary */
	if (i >= last || data[i] == NULL || data[i] == DELETED ||
	    ![data[i]->key isEqual: key]) {
		struct of_dictionary_hashtable_bucket *bucket;

		[self _resizeForCount: count + 1];

		mutations++;
		last = size;

		for (i = hash & (size - 1); i < last && data[i] != NULL &&
		    data[i] != DELETED; i++);








|







134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
	}

	/* Key not in dictionary */
	if (i >= last || data[i] == NULL || data[i] == DELETED ||
	    ![data[i]->key isEqual: key]) {
		struct of_dictionary_hashtable_bucket *bucket;

		[self OF_resizeForCount: count + 1];

		mutations++;
		last = size;

		for (i = hash & (size - 1); i < last && data[i] != NULL &&
		    data[i] != DELETED; i++);

183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
	data[i]->object = [object retain];
	[old release];
}

- (void)setObject: (id)object
	   forKey: (id)key
{
	[self _setObject: object
		  forKey: key
		 copyKey: YES];
}

- (void)removeObjectForKey: (id)key
{
	uint32_t i, hash, last;

	if (key == nil)







|
|
|







183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
	data[i]->object = [object retain];
	[old release];
}

- (void)setObject: (id)object
	   forKey: (id)key
{
	[self OF_setObject: object
		    forKey: key
		   copyKey: YES];
}

- (void)removeObjectForKey: (id)key
{
	uint32_t i, hash, last;

	if (key == nil)
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
			[data[i]->key release];
			[data[i]->object release];
			[self freeMemory: data[i]];
			data[i] = DELETED;

			count--;
			mutations++;
			[self _resizeForCount: count];

			return;
		}
	}

	if (i < last)
		return;







|







212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
			[data[i]->key release];
			[data[i]->object release];
			[self freeMemory: data[i]];
			data[i] = DELETED;

			count--;
			mutations++;
			[self OF_resizeForCount: count];

			return;
		}
	}

	if (i < last)
		return;
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
			[data[i]->key release];
			[data[i]->object release];
			[self freeMemory: data[i]];
			data[i] = DELETED;

			count--;
			mutations++;
			[self _resizeForCount: count];

			return;
		}
	}
}

- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state







|







236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
			[data[i]->key release];
			[data[i]->object release];
			[self freeMemory: data[i]];
			data[i] = DELETED;

			count--;
			mutations++;
			[self OF_resizeForCount: count];

			return;
		}
	}
}

- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state