From 977c4a0f8cddfad7fd46b2c08c0f82bc6d442cb1 Mon Sep 17 00:00:00 2001 From: Tux Date: Tue, 19 Jan 2016 15:13:29 -0700 Subject: [PATCH] Micro-optimizations - PluginManager.dispatchCommand() avoids regex while splitting commands. Java 7 introduced an optimized String.split() that should be used instead (affects command dispatch). - Avoid regex in getLocale() by changing from replaceAll(String, String) to replaceAll(char, char) - Don't attempt to format arguments when there are none provided - Don't create a data input stream for every plugin message we get from servers - Optimise replacing dashes in UUID's diff --git a/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java b/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java index 096538a7..54a65155 100644 --- a/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java +++ b/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java @@ -42,7 +42,6 @@ import org.yaml.snakeyaml.introspector.PropertyUtils; public class PluginManager { - private static final Pattern argsSplit = Pattern.compile( " " ); /*========================================================================*/ private final ProxyServer proxy; /*========================================================================*/ @@ -126,7 +125,7 @@ public class PluginManager */ public boolean dispatchCommand(CommandSender sender, String commandLine, List tabResults) { - String[] split = argsSplit.split( commandLine, -1 ); + String[] split = commandLine.split(" ", -1); // Check for chat that only contains " " if ( split.length == 0 ) { diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index 9f11f0a2..c8d1d225 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -518,7 +518,9 @@ public class BungeeCord extends ProxyServer String translation = ""; try { - translation = MessageFormat.format( customBundle != null && customBundle.containsKey( name ) ? customBundle.getString( name ) : baseBundle.getString( name ), args ); + final String string = customBundle != null && customBundle.containsKey( name ) ? customBundle.getString( name ) : baseBundle.getString( name ); + + translation = ( args.length == 0 ) ? string : MessageFormat.format( string, args ); } catch ( MissingResourceException ex ) { } diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index d4c58098..30f8a7df 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -224,7 +224,6 @@ public class DownstreamBridge extends PacketHandler @Override public void handle(PluginMessage pluginMessage) throws Exception { - DataInput in = pluginMessage.getStream(); PluginMessageEvent event = new PluginMessageEvent( server, con, pluginMessage.getTag(), pluginMessage.getData().clone() ); if ( bungee.getPluginManager().callEvent( event ).isCancelled() ) @@ -251,6 +250,7 @@ public class DownstreamBridge extends PacketHandler if ( pluginMessage.getTag().equals( "BungeeCord" ) ) { + DataInput in = pluginMessage.getStream(); ByteArrayDataOutput out = ByteStreams.newDataOutput(); String subChannel = in.readUTF(); -- 2.18.0