javaprims.h (_Jv_Utf8Const): Change struct to a class, with private fields and access methods.

* gcj/javaprims.h (_Jv_Utf8Const): Change struct to a class,
	with private fields and access methods.
	(_Jv_NewStringUTF, _Jv_hashUtf8String): New function declarations.
	* gcj/cni.h (_Jv_NewStringUTF): Move to javaprims.h.
	* prims.cc (_Jv_Utf8COnst::init): New method implementation.
	( _Jv_makeUtf8Const): Rewrite using new constructors.
	(hashUtf8String): Rename to +_Jv_hashUtf8String and make non-static.
	* defineclass.cc: Use new _Utf8Const access/convenience methods.
	* jni.cc: Likewise.
	* resolve.cc: Likewise.
	* gcj/field.h: Likewise.
	* include/jvm.h: Likewise.
	* java/lang/Class.h: Likewise.
	* java/lang/natClass.cc: Likwise.
	* java/lang/natClassLoader.cc: Likewise
	* java/lang/reflect/natMethod.cc: Likewise
	* verify.cc: Likewise.
	(_Jv_BytecodeVerifier::make_utf8_const):  Optimize.
	(~_Jv_BytecodeVerifier):  Don't need second _Jv_Free call.

From-SVN: r85854
This commit is contained in:
Per Bothner
2004-08-11 23:53:42 -07:00
committed by Per Bothner
parent fbac6f3cf5
commit b4d49f49bf
14 changed files with 163 additions and 117 deletions
+15 -8
View File
@@ -255,8 +255,8 @@ _Jv_strLengthUtf8(char* str, int len)
/* Calculate a hash value for a string encoded in Utf8 format.
* This returns the same hash value as specified or java.lang.String.hashCode.
*/
static jint
hashUtf8String (char* str, int len)
jint
_Jv_hashUtf8String (char* str, int len)
{
unsigned char* ptr = (unsigned char*) str;
unsigned char* limit = ptr + len;
@@ -272,17 +272,24 @@ hashUtf8String (char* str, int len)
return hash;
}
void
_Jv_Utf8Const::init(char *s, int len)
{
::memcpy (data, s, len);
data[len] = 0;
length = len;
hash = _Jv_hashUtf8String (s, len) & 0xFFFF;
}
_Jv_Utf8Const *
_Jv_makeUtf8Const (char* s, int len)
{
if (len < 0)
len = strlen (s);
Utf8Const* m = (Utf8Const*) _Jv_AllocBytes (sizeof(Utf8Const) + len + 1);
memcpy (m->data, s, len);
m->data[len] = 0;
m->length = len;
m->hash = hashUtf8String (s, len) & 0xFFFF;
return (m);
Utf8Const* m
= (Utf8Const*) _Jv_AllocBytes (_Jv_Utf8Const::space_needed(s, len));
m->init(s, len);
return m;
}
_Jv_Utf8Const *