Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 44728 invoked from network); 31 Jul 2005 08:04:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 31 Jul 2005 08:04:46 -0000 Received: (qmail 65818 invoked by uid 500); 31 Jul 2005 08:04:46 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 65763 invoked by uid 500); 31 Jul 2005 08:04:45 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 65750 invoked by uid 99); 31 Jul 2005 08:04:45 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 31 Jul 2005 01:04:45 -0700 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 31 Jul 2005 01:04:37 -0700 Received: (qmail 44664 invoked by uid 65534); 31 Jul 2005 08:04:44 -0000 Message-ID: <20050731080444.44663.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r226615 - /directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/util/MutableString.java Date: Sun, 31 Jul 2005 08:04:44 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.2 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: elecharny Date: Sun Jul 31 01:04:41 2005 New Revision: 226615 URL: http://svn.apache.org/viewcvs?rev=226615&view=rev Log: The length now contains the number of bytes of the string, not the number of chars. Added the method to get this length 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=226615&r1=226614&r2=226615&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 Sun Jul 31 01:04:41 2005 @@ -17,7 +17,7 @@ package org.apache.asn1.util; /** - * A Mutable version of the String class. This mutable Strins can be + * A Mutable version of the String class. This mutable String can be * stored in a pool. * * @author Apache Directory Project @@ -26,7 +26,11 @@ /** The string is stored in a char array */ private char[] string; - /** Actual length of the string */ + /** We also store the byte array for performance sake */ + private byte[] data; + + /** Actual length of the string. Be aware that it's a number of bytes, + * not a number of chars ! */ private int length; /** A null MutableString */ @@ -50,7 +54,7 @@ */ public MutableString(String string) { - this(string.getBytes()); + this( string.getBytes() ); } /** @@ -80,15 +84,7 @@ */ public MutableString(byte[] bytes) { - length = StringUtils.countChars(bytes); - string = new char[length]; - int pos = 0; - - for ( int i = 0; i < length; i++ ) - { - string[i] = StringUtils.bytesToChar(bytes, pos); - pos += StringUtils.countBytesPerChar(bytes, pos); - } + setData( bytes ); } /** @@ -99,13 +95,15 @@ */ public void setData(byte[] bytes) { - length = StringUtils.countChars(bytes); + data = bytes; + length = bytes.length; + int charLength = StringUtils.countChars(bytes); - string = new char[length]; + string = new char[charLength]; int pos = 0; - for ( int i = 0; i < length; i++ ) + for ( int i = 0; i < charLength; i++ ) { string[i] = StringUtils.bytesToChar(bytes, pos); pos += StringUtils.countBytesPerChar(bytes, pos); @@ -113,7 +111,8 @@ } /** - * @return Returns the length. + * @return Returns the length, as a number of bytes, not a number + * of chars. */ public int getLength() { @@ -121,10 +120,18 @@ } /** + * @return Returns the data. + */ + public byte[] getData() + { + return data; + } + + /** * Return a native String representation of the MutableString. */ public String toString() { - return length == 0 ? "" : new String(string, 0, length); + return length == 0 ? "" : new String(data, 0, length); } }