Skip to content

Commit

Permalink
Use StringTokenizer on BlockPos deserialization (on avarage, 25-30% f…
Browse files Browse the repository at this point in the history
…aster than normal String::split )
  • Loading branch information
EverNife committed Aug 8, 2024
1 parent b34c7fb commit 3c6f489
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;

import java.util.StringTokenizer;

@Getter
@EqualsAndHashCode
public class BlockPos implements Comparable<BlockPos> {
Expand Down Expand Up @@ -219,8 +221,12 @@ public String serialize(){
}

public static BlockPos deserialize(String string){
String[] split = string.split("\\|");
return at(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]));
StringTokenizer tokenizer = new StringTokenizer(string, "|");
return new BlockPos(
Integer.parseInt(tokenizer.nextToken()),
Integer.parseInt(tokenizer.nextToken()),
Integer.parseInt(tokenizer.nextToken())
);
}

}

0 comments on commit 3c6f489

Please sign in to comment.