private void BaseGroupSwitch(DataColumn[] oldArray, int oldLength, DataColumn[] newArray, int newLength)
{
// We're doing a smart diff of oldArray and newArray to find out what
// should be removed. We'll pass through oldArray and see if it exists
// in newArray, and if not, do remove work. newBase is an opt. in case
// the arrays have similar prefixes.
int newBase = 0;
for (int oldCur = 0; oldCur < oldLength; oldCur++)
{
bool found = false;
for (int newCur = newBase; newCur < newLength; newCur++)
{
if (oldArray[oldCur] == newArray[newCur])
{
if (newBase == newCur)
{
newBase++;
}
found = true;
break;
}
}
if (!found)
{
// This means it's in oldArray and not newArray. Remove it.
if (oldArray[oldCur].Table == _table)
{
BaseRemove(oldArray[oldCur]);
_list.Remove(oldArray[oldCur]);
oldArray[oldCur].SetOrdinalInternal(-1);
}
}
}
// Now, let's pass through news and those that don't belong, add them.
for (int newCur = 0; newCur < newLength; newCur++)
{
if (newArray[newCur].Table != _table)
{
BaseAdd(newArray[newCur]);
_list.Add(newArray[newCur]);
}
newArray[newCur].SetOrdinalInternal(newCur);
}
}