You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/06/10 08:18:40 UTC
svn commit: r189904 -
/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/MutableString.java
Author: elecharny
Date: Thu Jun 9 23:18:39 2005
New Revision: 189904
URL: http://svn.apache.org/viewcvs?rev=189904&view=rev
Log:
Changed the class to allocate the exact number of chars necessary to store the string.
The previous implementation allocated chunks of 16 chars.
Modified:
directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/MutableString.java
Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/MutableString.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/MutableString.java?rev=189904&r1=189903&r2=189904&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/MutableString.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/MutableString.java Thu Jun 9 23:18:39 2005
@@ -37,11 +37,11 @@
public transient static final boolean STREAMED = true;
/**
- * Creates a MutableString, with a default length of 16.
+ * Creates a MutableString.
*/
public MutableString()
{
- string = new char[16];
+ string = null;
length = 0;
}
@@ -68,18 +68,12 @@
/**
* Creates a MutableString with a value. The stored string
* is coded in Unicode, so the bytes *MUST* be valid !
- *
- * The char array size will be equal to 16, 32, 64 ... depending on
- * the string length to store. (some memory is lost, but this is the
- * price to pay for a performant pool mechanism : we are not going to
- * create a pool for each size !)
- *
* @param bytes The value to store.
*/
public MutableString(byte[] bytes)
{
length = StringUtils.countChars(bytes);
- string = new char[16 * (1 + length / 16)];
+ string = new char[length];
int pos = 0;
for ( int i = 0; i < length; i++ )
@@ -98,6 +92,10 @@
public void setData(byte[] bytes)
{
length = StringUtils.countChars(bytes);
+
+ string = new char[bytes.length];
+ this.length = bytes.length;
+
int pos = 0;
for ( int i = 0; i < length; i++ )
@@ -112,6 +110,6 @@
*/
public String toString()
{
- return new String(string, 0, length);
+ return length == 0 ? "" : new String(string, 0, length);
}
}