Matthew Toseland wrote:
> Can't we just clear() it? What does lint4j have against
> StringBuffer.setLength() exactly?
>
Because I didn't see nor do I see a clear() method in the docs for
StringBuffer nor did lint4j suggest it and I'm still a relative newb to
the Java API?
lint4j says it's a performance issue. See "Using
StringBuffer.setLength()" at http://www.jutils.com/checks/performance.html
> On Sun, Jul 09, 2006 at 11:21:58PM +0000, zothar at freenetproject.org wrote:
>
>> Author: zothar
>> Date: 2006-07-09 23:21:53 +0000 (Sun, 09 Jul 2006)
>> New Revision: 9533
>>
>> Modified:
>> trunk/freenet/src/freenet/clients/http/filter/HTMLFilter.java
>> trunk/freenet/src/freenet/support/FileLoggerHook.java
>> trunk/freenet/src/freenet/support/UpdatableSortedLinkedList.java
>> Log:
>> Make lint4j happier with StringBuffers by avoiding setLength()
>>
>> Modified: trunk/freenet/src/freenet/clients/http/filter/HTMLFilter.java
>> ===================================================================
>> --- trunk/freenet/src/freenet/clients/http/filter/HTMLFilter.java
>> 2006-07-09 22:47:52 UTC (rev 9532)
>> +++ trunk/freenet/src/freenet/clients/http/filter/HTMLFilter.java
>> 2006-07-09 23:21:53 UTC (rev 9533)
>> @@ -166,8 +166,8 @@
>>
>> saveText(b,
>> currentTag, w, this);
>>
>> - b.setLength(0);
>> -
>> balt.setLength(0);
>> + b = new
>> StringBuffer(100);
>> + balt = new
>> StringBuffer(4000);
>> mode = INTAG;
>> } else {
>> b.append(c);
>> @@ -178,21 +178,21 @@
>> if
>> (HTMLDecoder.isWhitespace(c)) {
>>
>> splitTag.add(b.toString());
>> mode =
>> INTAGWHITESPACE;
>> - b.setLength(0);
>> + b = new
>> StringBuffer(100);
>> } else if ((c == '<')
>> && Character.isWhitespace(balt.charAt(0))) {
>> // Previous was
>> an un-escaped < in a script.
>> saveText(b,
>> currentTag, w, this);
>>
>> -
>> balt.setLength(0);
>> - b.setLength(0);
>> + balt = new
>> StringBuffer(4000);
>> + b = new
>> StringBuffer(100);
>>
>> splitTag.clear();
>> } else if (c == '>') {
>>
>> splitTag.add(b.toString());
>> - b.setLength(0);
>> + b = new
>> StringBuffer(100);
>>
>> processTag(splitTag, w, this);
>> currentTag =
>> (String)splitTag.get(0);
>>
>> splitTag.clear();
>> -
>> balt.setLength(0);
>> + balt = new
>> StringBuffer(4000);
>> mode = INTEXT;
>> } else if (
>> (b.length() ==
>> 2)
>> @@ -228,9 +228,9 @@
>>
>> w.write(
>>
>> "<!-- Tags in string attribute -->");
>>
>> splitTag.clear();
>> -
>> b.setLength(0);
>> +
>> b = new StringBuffer(100);
>>
>> mode = INTEXT;
>> -
>> balt.setLength(0);
>> +
>> balt = new StringBuffer(4000);
>>
>> // End tag now
>> } else {
>>
>> killTag = true;
>> @@ -257,8 +257,8 @@
>>
>> w.write(
>>
>> "<!-- Tags in string attribute -->");
>>
>> splitTag.clear();
>> -
>> b.setLength(0);
>> -
>> balt.setLength(0);
>> +
>> b = new StringBuffer(100);
>> +
>> balt = new StringBuffer(4000);
>>
>> mode = INTEXT;
>>
>> // End tag now
>> } else {
>> @@ -303,7 +303,7 @@
>> case INTAGCOMMENTCLOSING :
>> if (c == '>') {
>> saveComment(b,
>> w, this);
>> - b.setLength(0);
>> + b = new
>> StringBuffer(100);
>> mode = INTEXT;
>> }
>> break;
>> @@ -321,14 +321,14 @@
>> killTag = false;
>> currentTag =
>> (String)splitTag.get(0);
>>
>> splitTag.clear();
>> - b.setLength(0);
>> -
>> balt.setLength(0);
>> + b = new
>> StringBuffer(100);
>> + balt = new
>> StringBuffer(4000);
>> mode = INTEXT;
>> } else if ((c == '<')
>> && Character.isWhitespace(balt.charAt(0))) {
>> // Previous was
>> an un-escaped < in a script.
>> saveText(balt,
>> currentTag, w, this);
>> -
>> balt.setLength(0);
>> - b.setLength(0);
>> + balt = new
>> StringBuffer(4000);
>> + b = new
>> StringBuffer(100);
>>
>> splitTag.clear();
>> mode = INTAG;
>> } else if
>> (HTMLDecoder.isWhitespace(c)) {
>>
>> Modified: trunk/freenet/src/freenet/support/FileLoggerHook.java
>> ===================================================================
>> --- trunk/freenet/src/freenet/support/FileLoggerHook.java 2006-07-09
>> 22:47:52 UTC (rev 9532)
>> +++ trunk/freenet/src/freenet/support/FileLoggerHook.java 2006-07-09
>> 23:21:53 UTC (rev 9533)
>> @@ -716,7 +716,7 @@
>> if (sb.length() > 0) {
>> strVec.addElement(sb.toString());
>> fmtVec.addElement(new Integer(0));
>> - sb.setLength(0);
>> + sb = new StringBuffer();
>> }
>> fmtVec.addElement(new Integer(numberOf(f[i])));
>> } else if (f[i] == '\\') {
>> @@ -729,7 +729,7 @@
>> if (sb.length() > 0) {
>> strVec.addElement(sb.toString());
>> fmtVec.addElement(new Integer(0));
>> - sb.setLength(0);
>> + sb = new StringBuffer();
>> }
>>
>> this.fmt = new int[fmtVec.size()];
>>
>> Modified: trunk/freenet/src/freenet/support/UpdatableSortedLinkedList.java
>> ===================================================================
>> --- trunk/freenet/src/freenet/support/UpdatableSortedLinkedList.java
>> 2006-07-09 22:47:52 UTC (rev 9532)
>> +++ trunk/freenet/src/freenet/support/UpdatableSortedLinkedList.java
>> 2006-07-09 23:21:53 UTC (rev 9533)
>> @@ -54,13 +54,10 @@
>> throw new IllegalStateException("impossible");
>> }
>>
>> - private StringBuffer sb = new StringBuffer(1000);
>> -
>> protected synchronized void checkList() {
>> // FIXME once satisfied that this works, make it only happen
>> occasionally
>> int statedLength = list.size();
>> int realLength = 0;
>> - sb.setLength(0);
>> for(Enumeration e = list.elements();e.hasMoreElements();) {
>> UpdatableSortedLinkedListItem i =
>> (UpdatableSortedLinkedListItem) e.nextElement();
>> // Sanity check for infinite looping
>>
>> _______________________________________________
>> cvs mailing list
>> cvs at freenetproject.org
>> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
>>
>>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> cvs mailing list
> cvs at freenetproject.org
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs