Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use String#intern for guild features and atoms #2235

Merged
merged 1 commit into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ private static Object unpackAtom(ByteBuffer buffer, Charset charset, int length)
case "true": return true;
case "false": return false;
case "nil": return null;
default: return value;
default: return value.intern();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ public GuildImpl createGuild(long guildId, DataObject guildJson, TLongObjectMap<
guildView.getMap().put(guildId, guildObj);
}

guildObj.setFeatures(featuresArray.map(it ->
StreamSupport.stream(it.spliterator(), false)
.map(String::valueOf)
.collect(Collectors.toSet())
guildObj.setFeatures(featuresArray.map(array ->
array.stream(DataArray::getString)
.map(String::intern) // Prevent allocating the same feature string over and over
.collect(Collectors.toSet())
).orElse(Collections.emptySet()));

SnowflakeCacheViewImpl<Role> roleView = guildObj.getRolesView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

public class GuildUpdateHandler extends SocketHandler
{
Expand Down Expand Up @@ -94,7 +93,7 @@ protected Long handleInternally(DataObject content)
if (!content.isNull("features"))
{
DataArray featureArr = content.getArray("features");
features = StreamSupport.stream(featureArr.spliterator(), false).map(String::valueOf).collect(Collectors.toSet());
features = featureArr.stream(DataArray::getString).map(String::intern).collect(Collectors.toSet());
}
else
{
Expand Down