From eebdb4a7a38173ec694221b6afdf27a535cd56d1 Mon Sep 17 00:00:00 2001 From: Konstantin Shandurenko Date: Thu, 31 Mar 2022 20:48:43 +0300 Subject: [PATCH] Reducing allocations count when working with bounding boxes (#843) --- src/main/java/net/minestom/server/collision/BoundingBox.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/minestom/server/collision/BoundingBox.java b/src/main/java/net/minestom/server/collision/BoundingBox.java index 6cf56bb0c..ea42524c4 100644 --- a/src/main/java/net/minestom/server/collision/BoundingBox.java +++ b/src/main/java/net/minestom/server/collision/BoundingBox.java @@ -13,6 +13,7 @@ import org.jetbrains.annotations.NotNull; public final class BoundingBox implements Shape { private final double width, height, depth; private final Point offset; + private Point relativeEnd; BoundingBox(double width, double height, double depth, Point offset) { this.width = width; @@ -73,7 +74,9 @@ public final class BoundingBox implements Shape { @Override public @NotNull Point relativeEnd() { - return offset.add(width, height, depth); + Point relativeEnd = this.relativeEnd; + if (relativeEnd == null) this.relativeEnd = relativeEnd = offset.add(width, height, depth); + return relativeEnd; } @Override