| author | Benjamin Muskalla | 2012-08-25 12:19:05 (EDT) |
|---|---|---|
| committer | Steffen Pingel | 2012-09-09 20:14:43 (EDT) |
| commit | 9ca41a88ac078defb074f51a737c0f94c358874b (patch) (side-by-side diff) | |
| tree | f5c3ba7e1189df75a9c91e845bd3c247149cd00c | |
| parent | 01852c680b85dfaf4e446bef9168af2181be63da (diff) | |
| download | org.eclipse.mylyn.commons-9ca41a88ac078defb074f51a737c0f94c358874b.zip org.eclipse.mylyn.commons-9ca41a88ac078defb074f51a737c0f94c358874b.tar.gz org.eclipse.mylyn.commons-9ca41a88ac078defb074f51a737c0f94c358874b.tar.bz2 | |
Trivial performance improvement in encode/decoderefs/changes/54/7254/3
Given synchronization on StringBuffer and the inability of JIT to
properly inline @append(string concatenation)@, this speeds up encoding
and decoding operations a little bit.
In a 1000 calls (after warmup), I measured an improvement of 2ms
average.
Change-Id: I4640df959c87627364018de2b9582b52191f13e6
| -rw-r--r-- | org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java index 6cea36a..d1d2763 100644 --- a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java +++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 Tasktop Technologies and others. + * Copyright (c) 2004, 2012 Tasktop Technologies and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -19,6 +19,7 @@ import org.osgi.framework.Version; /** * @since 3.0 * @author Steffen Pingel + * @author Benjamin Muskalla * @noinstantiate This class is not intended to be instantiated by clients. */ public class CoreUtil { @@ -247,8 +248,8 @@ public class CoreUtil { */ public static String decode(String text) { boolean escaped = false; - StringBuffer sb = new StringBuffer(text.length()); - StringBuffer escapedText = new StringBuffer(4); + StringBuilder sb = new StringBuilder(text.length()); + StringBuilder escapedText = new StringBuilder(4); char[] chars = text.toCharArray(); for (char c : chars) { if (c >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '.') { @@ -289,13 +290,15 @@ public class CoreUtil { * @since 3.8 */ public static String encode(String text) { - StringBuffer sb = new StringBuffer(text.length()); + StringBuilder sb = new StringBuilder(text.length()); char[] chars = text.toCharArray(); for (char c : chars) { if (c >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '.') { sb.append(c); } else { - sb.append("%" + Integer.toHexString(c).toUpperCase() + "_"); //$NON-NLS-1$ //$NON-NLS-2$ + sb.append("%"); //$NON-NLS-1$ + sb.append(Integer.toHexString(c).toUpperCase()); + sb.append("_"); //$NON-NLS-1$ } } return sb.toString(); |

