Differences From Artifact [27d37edf8c]:
- File
src/XMPPSRVEnumerator.m
— part of check-in
[0fe3ad2304]
at
2011-05-25 22:13:51
on branch trunk
— Correctly handle an empty priority list.
It should not exist, but this is no reason to not terminate. (user: js, size: 8316) [annotate] [blame] [check-ins using]
To Artifact [f3a2775abf]:
- File
src/XMPPSRVEnumerator.m
— part of check-in
[e240aaaf2a]
at
2011-05-25 22:41:26
on branch trunk
— Get rid of an unnecessary loop.
The loop is not required as we recalculate each entry's
accumulatedWeight on each call, thus there is always an entry that will
be found for the random number. (user: js, size: 8255) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
317 318 319 320 321 322 323 | } - (id)nextObject { XMPPSRVEntry *ret; of_list_object_t *iter; uint32_t totalWeight = 0; | < | < < < < | 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 | } - (id)nextObject { XMPPSRVEntry *ret; of_list_object_t *iter; uint32_t totalWeight = 0; if (done) return nil; if (listIter == NULL) listIter = [list lastListObject]; if (listIter == NULL) return nil; if (subListCopy == nil) subListCopy = [listIter->object copy]; for (iter = [subListCopy firstListObject]; iter != NULL; iter = iter->next) { totalWeight += [iter->object weight]; [iter->object setAccumulatedWeight: totalWeight]; } if ([subListCopy count] > 0) { 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]; break; } } } if ([subListCopy count] == 0) { [subListCopy release]; |
︙ | ︙ |