natString.cc (hashCode): Use cachedHashCode.
2003-03-29 Eric Blake <ebb9@email.byu.edu> Tom Tromey <tromey@redhat.com> * java/lang/natString.cc (hashCode): Use cachedHashCode. (init()): Removed. (charAt): Put index in exception. (contentEquals): New method. Include StringBuffer.h. * java/lang/String.java (cachedHashCode): New field. (String()): Follow classpath implementation. (init()): Removed. (contentEquals): Declare. (subSequence): Don't declare IndexOutIfBoundsException in throws clause. (matches, replaceFirst, replaceAll, split): New methods from Classpath. Co-Authored-By: Tom Tromey <tromey@redhat.com> From-SVN: r65037
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// natString.cc - Implementation of java.lang.String native methods.
|
||||
|
||||
/* Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation
|
||||
/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation
|
||||
|
||||
This file is part of libgcj.
|
||||
|
||||
@@ -20,6 +20,7 @@ details. */
|
||||
#include <java/lang/ArrayIndexOutOfBoundsException.h>
|
||||
#include <java/lang/StringIndexOutOfBoundsException.h>
|
||||
#include <java/lang/NullPointerException.h>
|
||||
#include <java/lang/StringBuffer.h>
|
||||
#include <java/io/ByteArrayOutputStream.h>
|
||||
#include <java/io/OutputStreamWriter.h>
|
||||
#include <java/io/ByteArrayInputStream.h>
|
||||
@@ -102,7 +103,9 @@ hashChars (jchar* ptr, jint length)
|
||||
jint
|
||||
java::lang::String::hashCode()
|
||||
{
|
||||
return hashChars(JvGetStringChars(this), length());
|
||||
if (cachedHashCode == 0)
|
||||
cachedHashCode = hashChars(JvGetStringChars(this), length());
|
||||
return cachedHashCode;
|
||||
}
|
||||
|
||||
jstring*
|
||||
@@ -428,14 +431,6 @@ _Jv_NewStringLatin1(const char *bytes, jsize len)
|
||||
return str;
|
||||
}
|
||||
|
||||
void
|
||||
java::lang::String::init ()
|
||||
{
|
||||
count = 0;
|
||||
boffset = sizeof(java::lang::String);
|
||||
data = this;
|
||||
}
|
||||
|
||||
void
|
||||
java::lang::String::init(jcharArray chars, jint offset, jint count,
|
||||
jboolean dont_copy)
|
||||
@@ -552,11 +547,30 @@ java::lang::String::equals(jobject anObject)
|
||||
return true;
|
||||
}
|
||||
|
||||
jboolean
|
||||
java::lang::String::contentEquals(java::lang::StringBuffer* buffer)
|
||||
{
|
||||
if (buffer == NULL)
|
||||
throw new NullPointerException;
|
||||
JvSynchronize sync(buffer);
|
||||
if (count != buffer->count)
|
||||
return false;
|
||||
if (data == buffer->value)
|
||||
return true; // Possible if shared.
|
||||
jint i = count;
|
||||
jchar *xptr = JvGetStringChars(this);
|
||||
jchar *yptr = elements(buffer->value);
|
||||
while (--i >= 0)
|
||||
if (*xptr++ != *yptr++)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
jchar
|
||||
java::lang::String::charAt(jint i)
|
||||
{
|
||||
if (i < 0 || i >= count)
|
||||
throw new java::lang::StringIndexOutOfBoundsException;
|
||||
throw new java::lang::StringIndexOutOfBoundsException(i);
|
||||
return JvGetStringChars(this)[i];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user