From 58dfa22afceb5abadd47963f4bba786e92e73766 Mon Sep 17 00:00:00 2001 From: Rob Stryker Date: Wed, 27 Nov 2024 15:34:28 -0500 Subject: [PATCH] Speed improvement in test classes. May contribute to upstream Signed-off-by: Rob Stryker --- .../jdt/core/compiler/CharOperation.java | 51 ++----------------- 1 file changed, 4 insertions(+), 47 deletions(-) diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/core/compiler/CharOperation.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/core/compiler/CharOperation.java index 5933dbd1958..1b27107d4ec 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/core/compiler/CharOperation.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/core/compiler/CharOperation.java @@ -3738,55 +3738,12 @@ public static final char[] replace( char[] toBeReplaced, char[] replacementChars) { - int max = array.length; - int replacedLength = toBeReplaced.length; - int replacementLength = replacementChars.length; - - int[] starts = new int[5]; - int occurrenceCount = 0; - - if (!equals(toBeReplaced, replacementChars)) { - - next : for (int i = 0; i < max;) { - int index = indexOf(toBeReplaced, array, true, i); - if (index == -1) { - i++; - continue next; - } - if (occurrenceCount == starts.length) { - System.arraycopy( - starts, - 0, - starts = new int[occurrenceCount * 2], - 0, - occurrenceCount); - } - starts[occurrenceCount++] = index; - i = index + replacedLength; - } - } - if (occurrenceCount == 0) + String s1 = new String(array); + String myRet = s1.replace(new String(toBeReplaced), new String(replacementChars)); + if( myRet.equals(s1)) { return array; - char[] result = - new char[max - + occurrenceCount * (replacementLength - replacedLength)]; - int inStart = 0, outStart = 0; - for (int i = 0; i < occurrenceCount; i++) { - int offset = starts[i] - inStart; - System.arraycopy(array, inStart, result, outStart, offset); - inStart += offset; - outStart += offset; - System.arraycopy( - replacementChars, - 0, - result, - outStart, - replacementLength); - inStart += replacedLength; - outStart += replacementLength; } - System.arraycopy(array, inStart, result, outStart, max - inStart); - return result; + return myRet.toCharArray(); } /**