ObjXMPP  Diff

Differences From Artifact [1b3191e9e7]:

To Artifact [27d37edf8c]:


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







-
+













-






+
+
+
-
+












-
+







}

- (id)nextObject
{
	XMPPSRVEntry *ret;
	of_list_object_t *iter;
	uint32_t totalWeight = 0;
	BOOL found = NO;
	BOOL loop = YES;

	if (done)
		return nil;

	if (listIter == NULL)
		listIter = [list lastListObject];

	if (listIter == NULL)
		return nil;

	if (subListCopy == nil)
		subListCopy = [listIter->object copy];

	/* FIXME: Handle empty subListCopy */
	for (iter = [subListCopy firstListObject]; iter != NULL;
	     iter = iter->next) {
		totalWeight += [iter->object weight];
		[iter->object setAccumulatedWeight: totalWeight];
	}

	if ([subListCopy count] == 0)
		loop = NO;

	while (!found) {
	while (loop) {
		uint32_t randomWeight;

		RAND_pseudo_bytes((uint8_t*)&randomWeight, sizeof(uint32_t));
		randomWeight %= (totalWeight + 1);

		for (iter = [subListCopy firstListObject]; iter != NULL;
		     iter = iter->next) {
			if ([iter->object accumulatedWeight] >= randomWeight) {
				ret = [[iter->object retain] autorelease];

				[subListCopy removeListObject: iter];

				found = YES;
				loop = NO;
				break;
			}
		}
	}

	if ([subListCopy count] == 0) {
		[subListCopy release];