mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
Avoid resizing of ArrayList in ChunkMap#getPlayers (#8416)
This commit is contained in:
parent
ad03c22822
commit
bb41ef89ff
1 changed files with 8 additions and 13 deletions
|
@ -13178,14 +13178,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
- throw chunkStorage.debugFuturesAndCreateReportedException(new IllegalStateException("null value previously set for chunk status"), s);
|
- throw chunkStorage.debugFuturesAndCreateReportedException(new IllegalStateException("null value previously set for chunk status"), s);
|
||||||
+ Object[] backingSet = players.getBackingSet();
|
+ Object[] backingSet = players.getBackingSet();
|
||||||
+ for (int i = 0, len = backingSet.length; i < len; ++i) {
|
+ for (int i = 0, len = backingSet.length; i < len; ++i) {
|
||||||
+ Object temp = backingSet[i];
|
+ if (!(backingSet[i] instanceof ServerPlayer player)) {
|
||||||
+ if (!(temp instanceof ServerPlayer)) {
|
|
||||||
+ continue;
|
+ continue;
|
||||||
}
|
}
|
||||||
-
|
-
|
||||||
- if (either == ChunkHolder.NOT_DONE_YET || either.right().isEmpty()) {
|
- if (either == ChunkHolder.NOT_DONE_YET || either.right().isEmpty()) {
|
||||||
- return completablefuture;
|
- return completablefuture;
|
||||||
+ ServerPlayer player = (ServerPlayer)temp;
|
|
||||||
+ if (!this.chunkMap.playerChunkManager.isChunkSent(player, this.pos.x, this.pos.z, onlyOnWatchDistanceEdge)) {
|
+ if (!this.chunkMap.playerChunkManager.isChunkSent(player, this.pos.x, this.pos.z, onlyOnWatchDistanceEdge)) {
|
||||||
+ continue;
|
+ continue;
|
||||||
}
|
}
|
||||||
|
@ -14473,29 +14471,26 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||||
- Set<ServerPlayer> set = this.playerMap.getPlayers(chunkPos.toLong());
|
- Set<ServerPlayer> set = this.playerMap.getPlayers(chunkPos.toLong());
|
||||||
- Builder<ServerPlayer> builder = ImmutableList.builder();
|
- Builder<ServerPlayer> builder = ImmutableList.builder();
|
||||||
- Iterator iterator = set.iterator();
|
- Iterator iterator = set.iterator();
|
||||||
-
|
|
||||||
- while (iterator.hasNext()) {
|
|
||||||
- ServerPlayer entityplayer = (ServerPlayer) iterator.next();
|
|
||||||
- SectionPos sectionposition = entityplayer.getLastSectionPos();
|
|
||||||
+ // Paper start - per player view distance
|
+ // Paper start - per player view distance
|
||||||
+ // there can be potential desync with player's last mapped section and the view distance map, so use the
|
+ // there can be potential desync with player's last mapped section and the view distance map, so use the
|
||||||
+ // view distance map here.
|
+ // view distance map here.
|
||||||
+ List<ServerPlayer> ret = new java.util.ArrayList<>(4);
|
|
||||||
+
|
|
||||||
+ com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> players = this.playerChunkManager.broadcastMap.getObjectsInRange(chunkPos);
|
+ com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<ServerPlayer> players = this.playerChunkManager.broadcastMap.getObjectsInRange(chunkPos);
|
||||||
+ if (players == null) {
|
+ if (players == null) {
|
||||||
+ return ret;
|
+ return java.util.Collections.emptyList();
|
||||||
+ }
|
+ }
|
||||||
|
|
||||||
|
- while (iterator.hasNext()) {
|
||||||
|
- ServerPlayer entityplayer = (ServerPlayer) iterator.next();
|
||||||
|
- SectionPos sectionposition = entityplayer.getLastSectionPos();
|
||||||
|
+ List<ServerPlayer> ret = new java.util.ArrayList<>(players.size());
|
||||||
|
|
||||||
- if (onlyOnWatchDistanceEdge && ChunkMap.isChunkOnRangeBorder(chunkPos.x, chunkPos.z, sectionposition.x(), sectionposition.z(), this.viewDistance) || !onlyOnWatchDistanceEdge && ChunkMap.isChunkInRange(chunkPos.x, chunkPos.z, sectionposition.x(), sectionposition.z(), this.viewDistance)) {
|
- if (onlyOnWatchDistanceEdge && ChunkMap.isChunkOnRangeBorder(chunkPos.x, chunkPos.z, sectionposition.x(), sectionposition.z(), this.viewDistance) || !onlyOnWatchDistanceEdge && ChunkMap.isChunkInRange(chunkPos.x, chunkPos.z, sectionposition.x(), sectionposition.z(), this.viewDistance)) {
|
||||||
- builder.add(entityplayer);
|
- builder.add(entityplayer);
|
||||||
+ Object[] backingSet = players.getBackingSet();
|
+ Object[] backingSet = players.getBackingSet();
|
||||||
+ for (int i = 0, len = backingSet.length; i < len; ++i) {
|
+ for (int i = 0, len = backingSet.length; i < len; ++i) {
|
||||||
+ Object temp = backingSet[i];
|
+ if (!(backingSet[i] instanceof ServerPlayer player)) {
|
||||||
+ if (!(temp instanceof ServerPlayer)) {
|
|
||||||
+ continue;
|
+ continue;
|
||||||
+ }
|
+ }
|
||||||
+ ServerPlayer player = (ServerPlayer)temp;
|
|
||||||
+ if (!this.playerChunkManager.isChunkSent(player, chunkPos.x, chunkPos.z, onlyOnWatchDistanceEdge)) {
|
+ if (!this.playerChunkManager.isChunkSent(player, chunkPos.x, chunkPos.z, onlyOnWatchDistanceEdge)) {
|
||||||
+ continue;
|
+ continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue