ObjFW  Diff

Differences From Artifact [dc60bfa33c]:

To Artifact [fd15d2ff3e]:


231
232
233
234
235
236
237






















238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253

	return self;
}

- initWithObjects: (OFArray*)objects
	  forKeys: (OFArray*)keys
{






















	self = [super init];

	@try {
		id *objectsCArray, *keysCArray;
		uint32_t i, j, newSize;

		keysCArray = [keys objects];
		objectsCArray = [objects objects];
		count = [keys count];

		if (count > UINT32_MAX)
			@throw [OFOutOfRangeException exceptionWithClass: isa];

		for (newSize = 1; newSize < count; newSize <<= 1);
		if (count * 4 / newSize >= 3)
			newSize <<= 1;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



<


<
<
|







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

	return self;
}

- initWithObjects: (OFArray*)objects
	  forKeys: (OFArray*)keys
{
	id ret;

	@try {
		if ([objects count] != [keys count])
			@throw [OFInvalidArgumentException
			    exceptionWithClass: isa];

		ret = [self initWithObjects: [objects objects]
				    forKeys: [keys objects]
				      count: [objects count]];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return ret;
}

- initWithObjects: (id*)objects
	  forKeys: (id*)keys
	    count: (size_t)count_
{
	self = [super init];

	@try {

		uint32_t i, j, newSize;



		count = count_;

		if (count > UINT32_MAX)
			@throw [OFOutOfRangeException exceptionWithClass: isa];

		for (newSize = 1; newSize < count; newSize <<= 1);
		if (count * 4 / newSize >= 3)
			newSize <<= 1;
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
			data[j] = NULL;

		size = newSize;

		for (i = 0; i < count; i++) {
			uint32_t hash, last;

			hash = [keysCArray[i] hash];
			last = size;

			for (j = hash & (size - 1); j < last && data[j] != NULL;
			    j++)
				if ([data[j]->key isEqual: keysCArray[i]])
					break;

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

				for (j = 0; j < last && data[j] != NULL; j++)
					if ([data[j]->key
					    isEqual: keysCArray[i]])
						break;
			}

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

				last = size;

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







|




|







|
<





|







281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301

302
303
304
305
306
307
308
309
310
311
312
313
314
			data[j] = NULL;

		size = newSize;

		for (i = 0; i < count; i++) {
			uint32_t hash, last;

			hash = [keys[i] hash];
			last = size;

			for (j = hash & (size - 1); j < last && data[j] != NULL;
			    j++)
				if ([data[j]->key isEqual: keys[i]])
					break;

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

				for (j = 0; j < last && data[j] != NULL; j++)
					if ([data[j]->key isEqual: keys[i]])

						break;
			}

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

				last = size;

				j = hash & (size - 1);
				for (; j < last && data[j] != NULL; j++);
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

				if (j >= last)
					@throw [OFOutOfRangeException
					    exceptionWithClass: isa];

				bucket =
				    [self allocMemoryWithSize: sizeof(*bucket)];
				key = [keysCArray[i] copy];

				bucket->key = key;
				bucket->object = [objectsCArray[i] retain];
				bucket->hash = hash;

				data[j] = bucket;

				continue;
			}

			/*
			 * The key is already in the dictionary. However, we
			 * just replace it so that the programmer gets the same
			 * behavior as if he'd call setObject:forKey: for each
			 * key/object pair.
			 */
			[objectsCArray[i] retain];
			[data[j]->object release];
			data[j]->object = objectsCArray[i];
		}
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;







|


|













|

|







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

				if (j >= last)
					@throw [OFOutOfRangeException
					    exceptionWithClass: isa];

				bucket =
				    [self allocMemoryWithSize: sizeof(*bucket)];
				key = [keys[i] copy];

				bucket->key = key;
				bucket->object = [objects[i] retain];
				bucket->hash = hash;

				data[j] = bucket;

				continue;
			}

			/*
			 * The key is already in the dictionary. However, we
			 * just replace it so that the programmer gets the same
			 * behavior as if he'd call setObject:forKey: for each
			 * key/object pair.
			 */
			[objects[i] retain];
			[data[j]->object release];
			data[j]->object = objects[i];
		}
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;