diff options
author | PJ Fanning <fanningpj@apache.org> | 2020-12-18 00:17:50 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2020-12-18 00:17:50 +0000 |
commit | 1e43266c7a83a051b6261859527d5f16596fe9d6 (patch) | |
tree | c0eb57ae8332d4fb7f7a659c69c26a0cb6003023 /src/java/org/apache | |
parent | bfade7c591a7ddb8eda643e4fb4932f7f8bad6a4 (diff) | |
download | poi-1e43266c7a83a051b6261859527d5f16596fe9d6.tar.gz poi-1e43266c7a83a051b6261859527d5f16596fe9d6.zip |
avoid string concats
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1884581 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r-- | src/java/org/apache/poi/util/POILogger.java | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/java/org/apache/poi/util/POILogger.java b/src/java/org/apache/poi/util/POILogger.java index 7a7e9ee135..da4fbb2d14 100644 --- a/src/java/org/apache/poi/util/POILogger.java +++ b/src/java/org/apache/poi/util/POILogger.java @@ -96,17 +96,26 @@ public interface POILogger { */ default void log(int level, Object... objs) { if (!check(level)) return; - StringBuilder sb = new StringBuilder(32); Throwable lastEx = null; - for (int i=0; i<objs.length; i++) { - if (i == objs.length-1 && objs[i] instanceof Throwable) { - lastEx = (Throwable)objs[i]; - } else { - sb.append(objs[i]); + String msg; + if (objs.length == 0) { + msg = ""; + } else if (objs.length == 1) { + if (objs[0] instanceof Throwable) { + lastEx = (Throwable)objs[0]; } + msg = objs[0].toString(); + } else { + StringBuilder sb = new StringBuilder(32); + for (int i=0; i<objs.length; i++) { + if (i == objs.length-1 && objs[i] instanceof Throwable) { + lastEx = (Throwable)objs[i]; + } else { + sb.append(objs[i]); + } + } + msg = sb.toString(); } - - String msg = sb.toString(); // log forging escape msg = msg.replaceAll("[\r\n]+", " "); |