RecordList Intersect

RecordList Intersect

  
Does anyone know a good way to compare two record lists for intersect values other than doing nested for loops?  We are currently comparing two recordlists of USER_MASTER records using nested for loops.  The record lists are populated from Active Directory Groups.  Performance seems to be a problem especially when we look at an all users group.  I've considered doing an extension in integration studio but am wondering if there is something already out there to do this?  Any help would be greatly appreciated.
a) dump them into temporarily tables and do a join on it.


b)if it's a sorted list, you can use just 1 "loop", instead of nesting.
the loop is an if-block with 2 counters

roughly:
0 counters set to 0
1. check if both counters not reach end of the lists.
2.  increase both counters if records are the same, and do something with records
3.  increase left if left < right, otherwise increase right (this depends on what you want to do with it)
4. go to check
5. now 1 of the lists has reached it's end, so the other list has to be dealt with.
6. done.

this loop is max list1.length + list2.length

ofcourse, with extension you can do it with less code