[kaffe] CVS kaffe (robilad): switched over to GNU Classpath's java.lang.String

Kaffe CVS cvs-commits at kaffe.org
Sun Jul 16 09:34:56 PDT 2006


PatchSet 7355 
Date: 2006/07/16 16:17:41
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
switched over to GNU Classpath's java.lang.String

2006-07-16  Dalibor Topic  <robilad at kaffe.org>

        Switched over to GNU Classpath's java.lang.String.

        * libraries/javalib/vmspecific/java/lang/String.java:
        Removed.

        * libraries/javalib/vmspecific/java/lang/VMString.java:
        Added new file from GNU Classpath. Adapted for Kaffe's
        native string interning.

        * include/Makefile.am (NOINSTALL_DERIVED_HDRS):
        Added java_lang_VMString.h.

        * kaffe/kaffevm/string.c (utf8Const2Java, utf8ConstEqualJavaString,
        stringHashValue, stringCompare) Use cachedHashCode field in String
        instead of hash.
        (string_isInterned) New helper function.
        (stringInternString, stringDestroy) Use string_isInterned rather than
        using the removed interned field of String.

        * kaffe/kaffevm/jni/jni-string.c (KaffeJNI_NewString):
        Don't set the interned field, it has been removed from String.

        * libraries/clib/native/String.c (java_lang_String_intern0) Renamed to ..
        (java_lang_VMString_intern) ... this.
        (java_lang_String_indexOf) Removed.

Members: 
	ChangeLog:1.4859->1.4860 
	include/Makefile.am:1.127->1.128 
	include/Makefile.in:1.284->1.285 
	kaffe/kaffevm/string.c:1.49->1.50 
	kaffe/kaffevm/jni/jni-string.c:1.16->1.17 
	libraries/clib/native/String.c:1.20->1.21 
	libraries/javalib/Makefile.am:1.441->1.442 
	libraries/javalib/Makefile.in:1.555->1.556 
	libraries/javalib/vmspecific/java/lang/String.java:1.4->1.5(DEAD) 
	libraries/javalib/vmspecific/java/lang/VMString.java:INITIAL->1.1 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4859 kaffe/ChangeLog:1.4860
--- kaffe/ChangeLog:1.4859	Sun Jul 16 15:04:06 2006
+++ kaffe/ChangeLog	Sun Jul 16 16:17:41 2006
@@ -1,5 +1,33 @@
 2006-07-16  Dalibor Topic  <robilad at kaffe.org>
 
+	Switched over to GNU Classpath's java.lang.String.
+
+	* libraries/javalib/vmspecific/java/lang/String.java:
+	Removed.
+
+	* libraries/javalib/vmspecific/java/lang/VMString.java:
+	Added new file from GNU Classpath. Adapted for Kaffe's
+	native string interning.
+
+	* include/Makefile.am (NOINSTALL_DERIVED_HDRS): 
+	Added java_lang_VMString.h.
+
+	* kaffe/kaffevm/string.c (utf8Const2Java, utf8ConstEqualJavaString,
+	stringHashValue, stringCompare) Use cachedHashCode field in String
+	instead of hash.
+	(string_isInterned) New helper function.
+	(stringInternString, stringDestroy) Use string_isInterned rather than
+	using the removed interned field of String.
+
+	* kaffe/kaffevm/jni/jni-string.c (KaffeJNI_NewString):
+	Don't set the interned field, it has been removed from String.
+
+	* libraries/clib/native/String.c (java_lang_String_intern0) Renamed to ..
+	(java_lang_VMString_intern) ... this.
+	(java_lang_String_indexOf) Removed.
+
+2006-07-16  Dalibor Topic  <robilad at kaffe.org>
+
 	libraries/extensions/comm/javalib/.cvsignore,
 	libraries/extensions/comm/javalib/Makefile.am,
 	libraries/extensions/comm/javalib/Makefile.in,
Index: kaffe/include/Makefile.am
diff -u kaffe/include/Makefile.am:1.127 kaffe/include/Makefile.am:1.128
--- kaffe/include/Makefile.am:1.127	Wed May 24 21:47:19 2006
+++ kaffe/include/Makefile.am	Sun Jul 16 16:17:45 2006
@@ -38,6 +38,7 @@
 	java_lang_VMClassLoader.h \
 	java_lang_VMRuntime.h \
 	java_lang_String.h \
+	java_lang_VMString.h \
 	java_lang_StackTraceElement.h \
 	java_lang_Thread.h \
 	java_lang_VMThread.h \
Index: kaffe/include/Makefile.in
diff -u kaffe/include/Makefile.in:1.284 kaffe/include/Makefile.in:1.285
--- kaffe/include/Makefile.in:1.284	Sun Jul 16 15:04:19 2006
+++ kaffe/include/Makefile.in	Sun Jul 16 16:17:45 2006
@@ -388,6 +388,7 @@
 	java_lang_VMClassLoader.h \
 	java_lang_VMRuntime.h \
 	java_lang_String.h \
+	java_lang_VMString.h \
 	java_lang_StackTraceElement.h \
 	java_lang_Thread.h \
 	java_lang_VMThread.h \
Index: kaffe/kaffe/kaffevm/string.c
diff -u kaffe/kaffe/kaffevm/string.c:1.49 kaffe/kaffe/kaffevm/string.c:1.50
--- kaffe/kaffe/kaffevm/string.c:1.49	Sat Apr 22 01:53:41 2006
+++ kaffe/kaffe/kaffevm/string.c	Sun Jul 16 16:17:46 2006
@@ -156,7 +156,7 @@
 	Hjava_lang_String* string;
 
 	string = utf8Const2JavaReplace(utf8, 0, 0);
-	unhand(string)->hash = utf8->hash;	/* why not, they're equal */
+	unhand(string)->cachedHashCode = utf8->hash;	/* why not, they're equal */
 	return(string);
 }
 
@@ -263,7 +263,7 @@
 
 #if 0
 	/* Question: would this optimization be worthwhile? */
-	if (unhand(string)->hash != 0 && unhand(string)->hash != utf8->hash) {
+	if (unhand(string)->cachedHashCode != 0 && unhand(string)->cachedHashCode != utf8->hash) {
 		return(0);
 	}
 #endif
@@ -308,6 +308,27 @@
 	lockStaticMutex(&stringLock);
 }
 
+/**
+ * Return the interned version of the String if
+ * it has been already interned, or NULL otherwise.
+ */
+static Hjava_lang_String *
+string_isInterned(Hjava_lang_String *string)
+{
+  Hjava_lang_String * result = NULL;
+
+  /* Lock intern table */
+  lockStaticMutex(&stringLock);
+
+  /* See if string is already in the table */
+  if (hashTable != NULL)
+    result = hashFind(hashTable, string);
+
+  unlockStaticMutex(&stringLock);
+
+  return(result);
+}
+
 /*
  * Return the interned version of a String object.
  * May or may not be the same String.
@@ -317,18 +338,16 @@
 {
 	Hjava_lang_String *temp;
 
+	temp = string_isInterned(string);
+
+	if(temp != NULL)
+	  return temp;
+
 	/* Lock intern table */
 	lockStaticMutex(&stringLock);
 
 	/* See if string is already in the table */
-	if (hashTable != NULL) {
-		Hjava_lang_String *string2;
-
-		if ((string2 = hashFind(hashTable, string)) != NULL) {
-			unlockStaticMutex(&stringLock);
-			return(string2);
-		}
-	} else {
+	if (hashTable == NULL) {
 		hashTable = hashInit(stringHashValue, stringCompare, stringAlloc, stringFree);
 		assert(hashTable != NULL);
 	}
@@ -340,7 +359,6 @@
 		return temp;
 	}
 	assert(temp == string);
-	unhand(string)->interned = true;
 
 	/* Unlock table and return new string */
 	unlockStaticMutex(&stringLock);
@@ -354,15 +372,11 @@
 void
 stringUninternString(Hjava_lang_String* string)
 {
+	if (!string_isInterned(string))
+	  return;
 
 	lockStaticMutex(&stringLock);
-	if (!unhand(string)->interned)
-	{
-	  unlockStaticMutex(&stringLock);
-	  return;
-	}
 	hashRemove(hashTable, string);
-	unhand(string)->interned = false;
 	unlockStaticMutex(&stringLock);
 }
 
@@ -378,13 +392,13 @@
 	jint hash;
 	int k;
 
-	if (unhand(string)->hash != 0) {
-		return(unhand(string)->hash);
+	if (unhand(string)->cachedHashCode != 0) {
+		return(unhand(string)->cachedHashCode);
 	}
 	for (k = hash = 0; k < STRING_SIZE(string); k++) {
 	       hash = (31 * hash) + STRING_DATA(string)[k];
 	}
-	unhand(string)->hash = hash;
+	unhand(string)->cachedHashCode = hash;
 	return(hash);
 }
 
@@ -402,9 +416,9 @@
 	if (STRING_SIZE(s1) != STRING_SIZE(s2)) {
 		return(1);
 	}
-	if (unhand(s1)->hash != 0
-	    && unhand(s2)->hash != 0
-	    && unhand(s1)->hash != unhand(s2)->hash) {
+	if (unhand(s1)->cachedHashCode != 0
+	    && unhand(s2)->cachedHashCode != 0
+	    && unhand(s1)->cachedHashCode != unhand(s2)->cachedHashCode) {
 		return(1);
 	}
 	for (k = 0; k < len; k++) {
@@ -525,7 +539,7 @@
         Hjava_lang_String* str = (Hjava_lang_String*)obj;
 
         /* unintern this string if necessary */
-        if (unhand(str)->interned == true) {
+        if (string_isInterned(str)) {
                 stringUninternString(str);
         }       
 }
Index: kaffe/kaffe/kaffevm/jni/jni-string.c
diff -u kaffe/kaffe/kaffevm/jni/jni-string.c:1.16 kaffe/kaffe/kaffevm/jni/jni-string.c:1.17
--- kaffe/kaffe/kaffevm/jni/jni-string.c:1.16	Sat Apr 22 01:53:41 2006
+++ kaffe/kaffe/kaffevm/jni/jni-string.c	Sun Jul 16 16:17:46 2006
@@ -46,7 +46,6 @@
   unhand(str)->offset = 0;
   unhand(str)->count = len;
   unhand(str)->value = (HArrayOfChar*)newArray(TYPE_CLASS(TYPE_Char), len);                   
-  unhand(str)->interned = 0;
   memcpy(STRING_DATA(str), data, len * sizeof(jchar));
 
   END_EXCEPTION_HANDLING();
Index: kaffe/libraries/clib/native/String.c
diff -u kaffe/libraries/clib/native/String.c:1.20 kaffe/libraries/clib/native/String.c:1.21
--- kaffe/libraries/clib/native/String.c:1.20	Mon Mar 20 21:46:21 2006
+++ kaffe/libraries/clib/native/String.c	Sun Jul 16 16:17:46 2006
@@ -4,10 +4,10 @@
  * Copyright (c) 1996, 1997
  *	Transvirtual Technologies, Inc.  All rights reserved.
  *
- * Copyright (c) 2005
+ * Copyright (c) 2005, 2006
  *      Kaffe.org contributors.  See ChangeLog for details. 
  *      All rights reserved.
- 8
+ *
  * See the file "license.terms" for information on usage and redistribution 
  * of this file. 
  */
@@ -23,7 +23,7 @@
 #include "java_lang_String.h"
 
 Hjava_lang_String*
-java_lang_String_intern0(Hjava_lang_String* str)
+java_lang_VMString_intern(Hjava_lang_String* str)
 {
 	Hjava_lang_String *ret = stringInternString(str);
 
@@ -33,72 +33,4 @@
 		throwError(&info);
 	}
 	return ret;
-}
-
-
-jint
-java_lang_String_indexOf(Hjava_lang_String* str, Hjava_lang_String* pat, jint offset)
-{
-  jchar *a;
-  jchar *p;
-
-  int   n;
-  int   m;
-  int   m2;
-  jint  i, k;
-  unsigned char  bs[256];
-  int *ibs;
-
-  if (pat == 0) {
-    SignalError("java.lang.NullPointerException", "");
-  }
-
-  if ( !str ) return -1;
-
-  a = &(unhand_array(unhand(str)->value)->body[unhand(str)->offset]);
-  n = unhand(str)->count;
-
-  p = &(unhand_array(unhand(pat)->value)->body[unhand(pat)->offset]);
-  m = unhand(pat)->count;
-  m2 = m * 2;
-
-  if ( m > n ) return -1;
-
-  if ( offset < 0 ) offset = 0;
-
-  if ( (m < 3) || (n < 128) || (m > 256) ) {
-	/*
-	 * If the pattern is too small, iterating the searched array would be
-	 * cheaper than to set up the badmatch table, or the pattern length exceeds
-	 * what we can store in the badmatch table, we revert to plain old brute force
-	 */
-	k = n - m+1;
-	for ( i=offset; i<k; i++ ) {
-	  if ( memcmp( &a[i], p, (size_t)m2) == 0 )
-		return i;		
-	}
-  }
-  else {
-	/*
-	 * Otherwise we use the Quick search variant of Boyer-Moore for 
-	 * O(n/m) lookup. Note that the (char) cast in the badmatch table access
-	 * is the justification for turning this into a native method
-	 */
-
-	/* set up the badmatch table */
-	k = (m << 24) | (m<<16) | (m<<8) | m;
-	for ( i=0, ibs = (int*)bs; i<64; i++ )
-	  ibs[i] = k; /* the default jump: m */
-	for ( i=0; i<m; i++ )
-	  bs[ (unsigned char)p[i] ] = m-i;
-
-	k= n - m + 1;
-	for ( i=offset; i < k; ) {
-	  if ( memcmp( &a[i], p, (size_t)m2) == 0 )
-		return i;
-	  i += bs[ (unsigned char)a[i+m] ];
-	}
-  }
-
-  return -1;
 }
Index: kaffe/libraries/javalib/Makefile.am
diff -u kaffe/libraries/javalib/Makefile.am:1.441 kaffe/libraries/javalib/Makefile.am:1.442
--- kaffe/libraries/javalib/Makefile.am:1.441	Sun Jul 16 14:06:31 2006
+++ kaffe/libraries/javalib/Makefile.am	Sun Jul 16 16:17:47 2006
@@ -229,7 +229,6 @@
 	vmspecific/java/io/VMObjectInputStream.java \
 	vmspecific/java/io/VMObjectStreamClass.java \
 	vmspecific/java/lang/Runtime.java \
-	vmspecific/java/lang/String.java \
 	vmspecific/java/lang/VMClass.java \
 	vmspecific/java/lang/VMClassLoader.java \
 	vmspecific/java/lang/VMCompiler.java \
@@ -239,6 +238,7 @@
 	vmspecific/java/lang/VMObject.java \
 	vmspecific/java/lang/VMProcess.java \
 	vmspecific/java/lang/VMRuntime.java \
+	vmspecific/java/lang/VMString.java \
 	vmspecific/java/lang/VMSystem.java \
 	vmspecific/java/lang/VMThread.java \
 	vmspecific/java/lang/VMThrowable.java \
Index: kaffe/libraries/javalib/Makefile.in
diff -u kaffe/libraries/javalib/Makefile.in:1.555 kaffe/libraries/javalib/Makefile.in:1.556
--- kaffe/libraries/javalib/Makefile.in:1.555	Sun Jul 16 15:05:00 2006
+++ kaffe/libraries/javalib/Makefile.in	Sun Jul 16 16:17:49 2006
@@ -543,7 +543,6 @@
 	vmspecific/java/io/VMObjectInputStream.java \
 	vmspecific/java/io/VMObjectStreamClass.java \
 	vmspecific/java/lang/Runtime.java \
-	vmspecific/java/lang/String.java \
 	vmspecific/java/lang/VMClass.java \
 	vmspecific/java/lang/VMClassLoader.java \
 	vmspecific/java/lang/VMCompiler.java \
@@ -553,6 +552,7 @@
 	vmspecific/java/lang/VMObject.java \
 	vmspecific/java/lang/VMProcess.java \
 	vmspecific/java/lang/VMRuntime.java \
+	vmspecific/java/lang/VMString.java \
 	vmspecific/java/lang/VMSystem.java \
 	vmspecific/java/lang/VMThread.java \
 	vmspecific/java/lang/VMThrowable.java \
===================================================================
Checking out kaffe/libraries/javalib/vmspecific/java/lang/String.java
RCS:  /home/cvs/kaffe/kaffe/libraries/javalib/vmspecific/java/lang/Attic/String.java,v
VERS: 1.4
***************
--- kaffe/libraries/javalib/vmspecific/java/lang/String.java	Sun Jul 16 16:34:54 2006
+++ /dev/null	Sun Aug  4 19:57:58 2002
@@ -1,1130 +0,0 @@
-/*
- * Java core library component.
- *
- * Copyright (c) 1997, 1998
- *      Transvirtual Technologies, Inc.  All rights reserved.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file.
- */
-
-package java.lang;
-
-import java.io.ByteArrayOutputStream;
-import java.io.CharConversionException;
-import java.io.Serializable;
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CodingErrorAction;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.IllegalCharsetNameException;
-import java.nio.charset.UnsupportedCharsetException;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.util.Comparator;
-import java.util.Locale;
-import java.util.regex.Pattern;
-
-public final class String implements Serializable, Comparable, CharSequence {
-
-	/**
-	 * Maximum slop (extra unused chars in the char[]) that
-	 * will be accepted in a StringBuffer -> String conversion.
-	 * This helps avoid certain pathological cases where lots of
-	 * extra buffer space is maintained for short strings that
-	 * were created from StringBuffer objects.
-	 */
-	static final int STRINGBUFFER_SLOP = 32;
-
-	// Note: value, offset, and count are not private, because
-	// StringBuffer uses them for faster access
-	final char[] value;
-	final int offset;
-	final int count;
-	private boolean interned;
-	private int hash;
-
-	/* This is what Sun's JDK1.1 "serialver java.lang.String" spits out */
-	private static final long serialVersionUID = -6849794470754667710L;
-
-	public static final Comparator CASE_INSENSITIVE_ORDER = new ICComp();
-
-	private static class ICComp implements Comparator, Serializable {
-	  public int compare(Object s1, Object s2) {
-	    return ((String)s1).compareToIgnoreCase((String)s2);
-	  }
-	}
-
-public String() {
-	value = new char[0];
-	offset = 0;
-	count = 0;
-}
-
-public String(String other) {
-	value = other.value;
-	offset = other.offset;
-	count = other.count;
-	hash = other.hash;
-}
-
-public String(StringBuffer sb) {
-	synchronized (sb) {
-		if (sb.value.length > sb.count + STRINGBUFFER_SLOP) {
-			value = new char[sb.count];
-			offset = 0;
-			count = sb.count;
-			sb.getChars(0, count, value, 0);
-		}
-		else {
-			value = sb.value;
-			offset = 0;
-			count = sb.count;
-			sb.shared = true;
-		}
-	}
-}
-
-public String(byte[] bytes) {
-	this(bytes, 0, bytes.length);
-}
-
-/* taken from GNU Classpath */
-  public String(byte[] data, String encoding)
-    throws UnsupportedEncodingException
-  {
-    this(data, 0, data.length, encoding);
-  }
-
-/**
- * @deprecated
- */
-public String(byte ascii[], int hibyte) {
-	this(ascii, hibyte, 0, ascii.length);
-}
-
-/* taken from GNU Claspath */
-  public String(byte[] data, int offset, int count)
-  {
-    if (offset < 0 || count < 0 || offset + count > data.length)
-      throw new StringIndexOutOfBoundsException();
-    int o, c;
-    char[] v;
-    String encoding;
-    try 
-	{
-	  encoding = System.getProperty("file.encoding");
-	  CharsetDecoder csd = Charset.forName(encoding).newDecoder();
-	  csd.onMalformedInput(CodingErrorAction.REPLACE);
-	  csd.onUnmappableCharacter(CodingErrorAction.REPLACE);
-	  CharBuffer cbuf = csd.decode(ByteBuffer.wrap(data, offset, count));
-	  if(cbuf.hasArray())
-	    {
-              v = cbuf.array();
-	      o = cbuf.position();
-	      c = cbuf.remaining();
-	    } else {
-	      // Doubt this will happen. But just in case.
-	      v = new char[cbuf.remaining()];
-	      cbuf.get(v);
-	      o = 0;
-	      c = v.length;
-	    }
-	} catch(Exception ex){
-	    // If anything goes wrong (System property not set,
-	    // NIO provider not available, etc)
-	    // Default to the 'safe' encoding ISO8859_1
-	    v = new char[count];
-	    o = 0;
-	    c = count;
-	    for (int i=0;i<count;i++)
-	      v[i] = (char)data[offset+i];
-	}
-    this.value = v;
-    this.offset = o;
-    this.count = c;
-  }
-
-/* taken from GNU Claspath */
-  public String(byte[] data, int offset, int count, String encoding)
-    throws UnsupportedEncodingException
-  {
-    if (offset < 0 || count < 0 || offset + count > data.length)
-      throw new StringIndexOutOfBoundsException();
-    try 
-      {
-        CharsetDecoder csd = Charset.forName(encoding).newDecoder();
-	csd.onMalformedInput(CodingErrorAction.REPLACE);
-	csd.onUnmappableCharacter(CodingErrorAction.REPLACE);
-	CharBuffer cbuf = csd.decode(ByteBuffer.wrap(data, offset, count));
- 	if(cbuf.hasArray())
- 	  {
- 	    value = cbuf.array();
-	    this.offset = cbuf.position();
-	    this.count = cbuf.remaining();
- 	  } else {
-	    // Doubt this will happen. But just in case.
-	    value = new char[cbuf.remaining()];
-	    cbuf.get(value);
-	    this.offset = 0;
-	    this.count = value.length;
-	  }
-      } catch(CharacterCodingException e){
-	  throw new UnsupportedEncodingException("Encoding: "+encoding+
-						 " not found.");	  
-      } catch(IllegalCharsetNameException e){
-	  throw new UnsupportedEncodingException("Encoding: "+encoding+
-						 " not found.");
-      } catch(UnsupportedCharsetException e){
-	  throw new UnsupportedEncodingException("Encoding: "+encoding+
-						 " not found.");
-      }    
-  }
-
-/**
- * @deprecated
- */
-public String( byte ascii[], int hibyte, int offset, int count) {
-	// Test needed to conform to the spec. - TIM
-	if (ascii == null) {
-		throw new NullPointerException();
-	}
-	value = new char[count];
-	this.offset = 0;
-	this.count = count;
-
-	hibyte = (hibyte & 0xFF) << 8;
-	for (int pos = 0; pos < count; pos++) {
-		value[pos]=(char)(hibyte | (ascii[pos+offset] & 0xFF));	
-	}
-}
-
-public String( char other[]) {
-	this( other, 0, other.length);
-}
-
-public String( char other[], int offset, int count) {
-	if (count < 0)
-		throw new StringIndexOutOfBoundsException();
-	value = new char[count];
-	this.offset = 0;
-	this.count = count;    
-	System.arraycopy( other, offset, value, 0, count);
-}
-
-String(int sIdx, int eIdx, char[] val) {
-	value  = val;
-	offset = sIdx;
-	count  = eIdx - sIdx;
-}
-
-public char charAt ( int index ) {
-	if (( index < 0) || ( index >= count))
-		throw new StringIndexOutOfBoundsException("index = "+index+", length="+count);
-
-	return value[offset+index];
-}
-
-public int compareTo(Object o) {
-	return compareTo((String)o);
-}
-
-public int compareTo( String s1) {
-	/* lexicographical comparison, assume they mean English lexiographical, since Character has no ordering */
-
-	int minLen = Math.min( count, s1.count);
-	char c, c1;
-
-	for ( int pos=0; pos<minLen; pos++) {
-		/* Can we guarantee that the Unicode '<' relation means also numerically '<'.. Probably, but just incase */
-		c = value[offset+pos]; c1 = s1.value[s1.offset+pos];
-		if ( c != c1) return ( c-c1);
-	}
-
-	/* Both equal up to min length, therefore check lengths for lexiographical ordering */
-	return ( count - s1.count);
-}
-
-public int compareToIgnoreCase(String that) {
-	return this.toUpperCase().toLowerCase().compareTo(
-		that.toUpperCase().toLowerCase());
-}
-
-public String concat(String str) {
-	if (str.count == 0) {
-		return (this);
-	}
-	char buf[] = new char[count + str.count];
-	getChars(0, count, buf, 0);
-	str.getChars(0, str.count, buf, count);
-	return (new String(0, buf.length, buf));
-}
-
-public static String copyValueOf( char data[]) {
-	return copyValueOf( data, 0, data.length);
-}
-
-public static String copyValueOf(char data[], int offset, int count) {
-	if (offset < 0 || count < 0 || offset + count > data.length) {
-		throw new IndexOutOfBoundsException();
-	}
-	char buf[]=new char[count];
-	if ( count > 0) {
-		System.arraycopy( data, offset, buf, 0, count);
-	}
-	return (new String( 0, count, buf));
-}
-
-public boolean endsWith( String suffix) {
-	return regionMatches( false, count-suffix.count, suffix, 0, suffix.count);
-}
-
-// This is one of the most frequently called methods; it must be as
-// efficient as possible.
-public boolean equals (Object anObject) {
-
-	if (anObject == this) {
-		return (true);
-	}
-	if (!(anObject instanceof String)) {
-		return (false);
-	}
-	final String that = (String)anObject;
-
-	if (this.count != that.count) {
-		return (false);
-	}
-
-	int i = this.offset;
-	int j = that.offset;
-	final int n = i + this.count;
-	final char[] this_value = this.value;
-	final char[] that_value = that.value;
-	for (; i < n; i++, j++) {
-		if (this_value[i] != that_value[j] ) {
-			return (false);
-		}
-	}
-	return (true);
-}
-
-// This also should be as fast as possible
-public boolean equalsIgnoreCase (String that) {
-	if (that == null || this.count != that.count) {
-		return (false);
-	}
-
-	int i = this.offset;
-	int j = that.offset;
-	final int n = i + this.count;
-	final char[] this_value = this.value;
-	final char[] that_value = that.value;
-	for (; i < n; i++, j++) {
-		if (this_value[i] != that_value[j]
-		   && Character.toUpperCase(this_value[i])
-		     != Character.toUpperCase(that_value[j])) {
-			return (false);
-		}
-	}
-	return (true);
-}
-
-    /* Taken from GNU Classpath */
-  public byte[] getBytes()
-  { 
-      try 
-	  {
-	      return getBytes(System.getProperty("file.encoding"));
-	  } catch(Exception e) {
-	      // XXX - Throw an error here? 
-	      // For now, default to the 'safe' encoding.
-	      byte[] bytes = new byte[count];
-	      for(int i=0;i<count;i++)
-		  bytes[i] = (byte)((value[offset+i] <= 0xFF)?
-				    value[offset+i]:'?');
-	      return bytes;
-      }
-  }
-
-    /* Taken from GNU Classpath */
-  public byte[] getBytes(String enc) throws UnsupportedEncodingException
-  {
-    try 
-      {
-	CharsetEncoder cse = Charset.forName(enc).newEncoder();
-	cse.onMalformedInput(CodingErrorAction.REPLACE);
-	cse.onUnmappableCharacter(CodingErrorAction.REPLACE);
-	ByteBuffer bbuf = cse.encode(CharBuffer.wrap(value, offset, count));
-	if(bbuf.hasArray())
-	  return bbuf.array();
-	
-	// Doubt this will happen. But just in case.
-	byte[] bytes = new byte[bbuf.remaining()];
-	bbuf.get(bytes);
-	return bytes;
-      } 
-    catch(IllegalCharsetNameException e)
-      {
-	throw new UnsupportedEncodingException("Encoding: " + enc
-					       + " not found.");
-      } 
-    catch(UnsupportedCharsetException e)
-      {
-	throw new UnsupportedEncodingException("Encoding: " + enc
-					       + " not found.");
-      } 
-    catch(CharacterCodingException e)
-      {
-	// This shouldn't ever happen.
-	throw (InternalError) new InternalError().initCause(e);
-      }	  
-  }
-
-/**
- * @deprecated
- */
-public void getBytes( int srcBegin, int srcEnd, byte dst[], int dstBegin) {
-	if (srcBegin < 0 
-	    || srcBegin > srcEnd
-	    ||  dstBegin < 0
-	    ||  dstBegin + (srcEnd - srcBegin) >  dst.length
-	    || srcEnd > offset + count) {
-		throw new IndexOutOfBoundsException("");
-	}
-	int len = srcEnd-srcBegin;
-	for (int pos = 0; pos < len; pos++) {
-		dst[dstBegin+pos] = (byte)value[offset+srcBegin+pos];
-	}
-}
-
-public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
-	System.arraycopy( value, offset+srcBegin, dst, dstBegin, srcEnd-srcBegin);
-}
-
-public int hashCode() {
-	if (hash == 0 && count > 0) {
-		int tempHash = 0;
-		final int stop = offset + count;
-		for (int index = offset; index < stop; index++) {
-			tempHash = (31 * tempHash) + value[index];
-		}
-		hash = tempHash;	// race condition here is ok
-	}
-	return hash;
-}
-
-public int indexOf( String str) {
-	return indexOf( str, 0);
-}
-
-native public int indexOf( String str, int sIdx);
-
-public int indexOf( int ch) {
-	return indexOf( ch, 0);
-}
-
-public int indexOf( int ch, int sIdx) {
-	char c = (char)ch;
-	if (sIdx < 0) { // calling indexOf with sIdx < 0 is apparently okay
-		sIdx = 0;
-	}
-	for (int pos=sIdx; pos<count; pos++) {
-		if ( value[offset+pos] == c )
-			return pos;
-	}
-
-	return -1;
-}
-
-public int lastIndexOf( String str) {
-	return lastIndexOf( str, count);
-}
-
-public int lastIndexOf( String str, int eIdx) {
-	int ic = str.offset+str.count-1;
-	int it = offset+eIdx+str.count-1;
-	int ma = 0;
-
-	if (it >= offset+count) {       // clip index
-		it = offset+count-1;
-	}
-
-	if (str.count == 0) {
-		return (eIdx < 0) ? -1 : (eIdx < count) ? eIdx : count;
-	}
-
-	for ( ; it>=offset; it--) {
-		if ( value[it] == str.value[ic] ) {
-			ic--;
-			if ( ++ma == str.count) {
-				return (it-offset);
-			}
-		}
-		else if (ma > 0) {
-			it++;
-			ma = 0;
-			ic = str.offset+str.count-1;
-		}
-	}
-	return -1;
-}
-
-public int lastIndexOf(int ch) {
-	return lastIndexOf( ch, count-1);
-}
-
-public int lastIndexOf(int ch, int eIdx) {
-	final char c = (char)ch;
-
-	/* If the character is out of range we'll never find it */
-	if ((int)c != ch) {
-		return (-1);
-	}
-
-	/* Clip the index to be within the valid range (if non-empty) */
-	if (eIdx >= count) {
-		eIdx = count - 1;
-	}
-	if (eIdx < 0) {
-		return(-1);
-	}
-
-	/* Search for character */
-	for (int pos = eIdx; pos >= 0; pos--) {
-		if ( value[offset+pos] == c) {
-			return (pos);
-		}
-	}
-	return (-1);
-}
-
-public int length() {
-	return count;
-}
-
-public boolean regionMatches(boolean ignoreCase, int thisOffset,
-		String that, int thatOffset, int len) {
-
-	// Check bounds
-	if ((thisOffset < 0 || thisOffset + len > this.count)
-	    || (thatOffset < 0 || thatOffset + len > that.count)) {
-		return false;
-	}
-
-	int thisPos = this.offset + thisOffset;
-	int thatPos = that.offset + thatOffset;
-	if (!ignoreCase) {
-		while (len-- > 0) {
-			if (this.value[thisPos] != that.value[thatPos]) {
-				return false;
-			}
-			thisPos++;
-			thatPos++;
-		}
-	} else {
-		while (len-- > 0) {
-			if (Character.toLowerCase(this.value[thisPos])
-			    != Character.toLowerCase(that.value[thatPos])
-			  && Character.toUpperCase(this.value[thisPos])
-			    != Character.toUpperCase(that.value[thatPos])) {
-				return false;
-			}
-			thisPos++;
-			thatPos++;
-		}
-	}
-	return true;
-}
-
-public boolean regionMatches( int toffset, String other, int ooffset, int len) {
-	return regionMatches( false, toffset, other, ooffset, len);
-}
-
-public String replace(char oldChar, char newChar) {
-	if (oldChar == newChar) {
-		return (this);
-	}
-
-	char buf[] = new char[count];
-	boolean replaced = false;
-
-	for (int pos = 0; pos < count; pos++) {
-		char cc = value[offset+pos];
-		if ( cc == oldChar) {
-			replaced = true;
-			buf[pos] = newChar;
-		}
-		else {
-			buf[pos] = cc;
-		}
-	}
-
-	if (!replaced) {
-		return (this);
-	}
-	else {
-		return (new String( 0, count, buf));
-	}
-}
-
-public boolean startsWith( String prefix) {
-	return regionMatches( false, 0, prefix, 0, prefix.count);
-}
-
-public boolean startsWith( String prefix, int toffset) {
-	return regionMatches( false, toffset, prefix, 0, prefix.count);
-}
-
-public String substring( int sIdx) {
-	return substring( sIdx, count);
-}
-
-/*
- * shared data
- */
-public String substring( int sIdx, int eIdx) {
-	if ( sIdx < 0)     throw new StringIndexOutOfBoundsException( sIdx);
-	if ( eIdx > count) throw new StringIndexOutOfBoundsException( eIdx);
-	if ( sIdx > eIdx)  throw new StringIndexOutOfBoundsException( eIdx-sIdx);
-

*** Patch too long, truncated ***




More information about the kaffe mailing list