ObjFW  Diff

Differences From Artifact [c74680827d]:

To Artifact [0791cedf2b]:


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
	}

	[self freeMemory: data];
	data = newdata;
	size = newsize;
}

- (id)setObject: (OFObject*)obj
	 forKey: (OFObject <OFCopying>*)key
{
	uint32_t i, hash, last;
	id old;

	if (key == nil || obj == nil)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];







|
|







75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
	}

	[self freeMemory: data];
	data = newdata;
	size = newsize;
}

- (void)setObject: (OFObject*)obj
	   forKey: (OFObject <OFCopying>*)key
{
	uint32_t i, hash, last;
	id old;

	if (key == nil || obj == nil)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];
155
156
157
158
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215

216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234

		b->key = key;
		b->object = obj;
		b->hash = hash;
		data[i] = b;
		count++;

		return nil;
	}

	old = data[i]->object;
	data[i]->object = [obj retain];

	return [old autorelease];
}

- (id)removeObjectForKey: (OFObject*)key
{
	uint32_t i, hash, last;
	id old;

	if (key == nil)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	hash = [key hash];
	last = size;

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

		if ([data[i]->key isEqual: key]) {
			old = data[i]->object;

			[data[i]->key release];

			[self freeMemory: data[i]];
			data[i] = DELETED;

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

			return [old autorelease];
		}
	}

	if (i < last)
		return nil;

	/* In case the last bucket is already used */
	last = hash & (size - 1);

	for (i = 0; i < last && data[i] != NULL; i++) {
		if (data[i] == DELETED)
			continue;

		if ([data[i]->key isEqual: key]) {
			old = data[i]->object;

			[data[i]->key release];

			[self freeMemory: data[i]];
			data[i] = DELETED;

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

			return [old autorelease];
		}
	}

	return nil;
}

- copy
{
	return [[OFDictionary alloc] initWithDictionary: self];
}








|




<
|


|


<













<
<

>







|




|









<
<

>







|


<
<







155
156
157
158
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
197
198
199
200
201
202
203
204
205
206
207
208
209


210
211
212
213
214
215
216
217
218
219
220
221


222
223
224
225
226
227
228

		b->key = key;
		b->object = obj;
		b->hash = hash;
		data[i] = b;
		count++;

		return;
	}

	old = data[i]->object;
	data[i]->object = [obj retain];

	[old release];
}

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


	if (key == nil)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	hash = [key hash];
	last = size;

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

		if ([data[i]->key isEqual: key]) {


			[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;

	/* In case the last bucket is already used */
	last = hash & (size - 1);

	for (i = 0; i < last && data[i] != NULL; i++) {
		if (data[i] == DELETED)
			continue;

		if ([data[i]->key isEqual: key]) {


			[data[i]->key release];
			[data[i]->object release];
			[self freeMemory: data[i]];
			data[i] = DELETED;

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

			return;
		}
	}


}

- copy
{
	return [[OFDictionary alloc] initWithDictionary: self];
}