Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [eclipse-dev] Beware of String#substring(...)

I would like to point you to the unfinished article draft I wrote that
discusses it:

http://www.cs.technion.ac.il/~genadyb/strings/strings.html

Genady 

-----Original Message-----
From: Jerome Lanneluc [mailto:jerome_lanneluc@xxxxxxxxxx] 
Sent: Friday, March 25, 2005 14:23
To: eclipse-dev@xxxxxxxxxxx
Subject: [eclipse-dev] Beware of String#substring(...)

I just noticed that String#substring(...) shares the underlying char array.
So if you have a big string, take a substring of it, throw away the big
string, you will still hold on the big char array.
A simple way to solve this is to make a copy of the substring using the
String(String) constructor.

I saved 550KB in JDT Core by changing the following code:
      String simpleName =
fullyQualifiedName.substring(fullQualifiedName.lastIndexOf('.'));
to
      String simpleName = new
String(fullyQualifiedName.substring(fullQualifiedName.lastIndexOf('.')));

Jerome

_______________________________________________
eclipse-dev mailing list
eclipse-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from
this list, visit http://dev.eclipse.org/mailman/listinfo/eclipse-dev




Back to the top