This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch: MAXPATHLEN usage - PR21821


Bryce McKinlay wrote:
David Daney wrote:

Bryce McKinlay wrote:

+ ::java::lang::StringBuffer *msg = new ::java::lang::StringBuffer (path);
+ msg->append (JvNewStringUTF (" ("));
+ msg->append (JvNewStringUTF (strerror (errno)));
+ msg->append (JvNewStringUTF (")"));
+ throw new ::java::io::FileNotFoundException (msg->toString ());



Shouldn't we now be using StringBuilder instead of StringBuffer in places like this?



Yeah, good point. It would be worth doing a pass over the entire library and substituting StringBuffer->StringBuilder everywhere.

For CNI code it would be even better to use a stack-allocated "RawStringBuilder" struct:

/* Hybrid C++/Java syntax */

struct RawStringBuilder {
  jarray_byte *value;
  jint count;

  public void append (...) { ...}
}

class StringBuiler {
  private RawStringBuilder builder;
  public inline StringBuilder append (...)
  {
    builder.append(...);
    return this;
  }
}

Use:
RawStringBuilder msg;
msg.append(...);
...

The compiler should generate calls to RawStringBuilder rather than
StringBuilder string appends.  It should also optimize uses of
StringBuffer *and* StringBuilder to RawStringBuilder when safe.

Another item for the wishlist ...  Of course the benefit might
be reduced by escape analysis.  But general escape analysis
won't be able to optimize StringBuffer to RawStringBuilder.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]