mirror of
https://github.com/osukey/osukey.git
synced 2025-05-17 19:47:33 +09:00
Reworked reopening last tab to no longer use recursion
A reviewer of the pull request was concerned about recursion. I changed the code to be iterative.
This commit is contained in:
parent
7b169c4f62
commit
2f8a085adf
@ -445,33 +445,47 @@ namespace osu.Game.Online.Chat
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string lastClosedChannelName = closedChannels.Last();
|
// This nested loop could be eliminated if a check was added so that
|
||||||
closedChannels.RemoveAt(closedChannels.Count - 1);
|
// when the code opens a channel it removes from the closedChannel list.
|
||||||
|
// However, this would require adding an O(|closeChannels|) work operation
|
||||||
// types did not work with existing enumerable interfaces funcitons like Contains
|
// every time the user joins a channel, which would make joining a channel
|
||||||
for (int i = 0; i < joinedChannels.Count; i++)
|
// slower. I wanted to centralize all major slowdowns so they
|
||||||
|
// can only occur if the user actually decides to use this feature.
|
||||||
|
for (int i = closedChannels.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
// If the user already joined the channel, try the next
|
string lastClosedChannelName = closedChannels.Last();
|
||||||
// channel in the list
|
closedChannels.RemoveAt(closedChannels.Count - 1);
|
||||||
if (joinedChannels[i].Name == lastClosedChannelName)
|
bool alreadyJoined = false;
|
||||||
|
// If the user already joined the channel, do not
|
||||||
|
// try to join it
|
||||||
|
for (int j = 0; j < joinedChannels.Count; j++)
|
||||||
{
|
{
|
||||||
JoinLastClosedChannel();
|
if (joinedChannels[j].Name == lastClosedChannelName)
|
||||||
return;
|
{
|
||||||
|
alreadyJoined = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (alreadyJoined == false)
|
||||||
|
{
|
||||||
|
Channel lastClosedChannel = AvailableChannels.FirstOrDefault(c => c.Name == lastClosedChannelName);
|
||||||
|
|
||||||
|
if (lastClosedChannel == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
JoinChannel(lastClosedChannel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel lastClosedChannel = AvailableChannels.FirstOrDefault(c => c.Name == lastClosedChannelName);
|
|
||||||
|
|
||||||
if (lastClosedChannel == null)
|
|
||||||
{
|
|
||||||
JoinLastClosedChannel();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
JoinChannel(lastClosedChannel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private long lastMessageId;
|
private long lastMessageId;
|
||||||
|
|
||||||
private bool channelsInitialised;
|
private bool channelsInitialised;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user