>ant/core/trunk/src/main/org/apache/tools/ant/util/StringUtils.java (original) >+++ ant/core/trunk/src/main/org/apache/tools/ant/util/StringUtils.java >+++ Sat Oct 22 10:27:25 2005 > >+ /** >+ * Checks that a string buffer ends up with a given string. It may sound trivial with the existing >+ * JDK API but the various implementation among JDKs can make those methods extremely resource intensive >+ * and perform poorly due to massive memory allocation and copying. See
See where? Jan >+ * @param buffer the buffer to perform the check on >+ * @param suffix the suffix >+ * @return <code>true</code> if the character sequence represented by the >+ * argument is a suffix of the character sequence represented by >+ * the StringBuffer object; <code>false</code> otherwise. Note that the >+ * result will be <code>true</code> if the argument is the >+ * empty string. >+ */ >+ public static boolean endsWith(StringBuffer buffer, String suffix) { >+ if (suffix.length() > buffer.length()) { >+ return false; >+ } >+ // this loop is done on purpose to avoid memory allocation performance problems on various JDKs >+ // StringBuffer.lastIndexOf() was introduced in jdk 1.4 and implementation is ok though does allocation/copying >+ // StringBuffer.toString().endsWith() does massive memory allocation/copying on JDK 1.5 >+ // See http://issues.apache.org/bugzilla/show_bug.cgi?id=37169 >+ int endIndex = suffix.length() - 1; >+ int bufferIndex = buffer.length() - 1; >+ while ( endIndex >= 0 ) { >+ if ( buffer.charAt(bufferIndex) != suffix.charAt(endIndex) ) { >+ return false; >+ } >+ bufferIndex--; >+ endIndex--; >+ } >+ return true; >+ } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]