mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-01-19 03:43:59 +08:00
javaprims.h (_Jv_FormatInt): New declaration.
* gcj/javaprims.h (_Jv_FormatInt): New declaration. * java/lang/natString.cc (_JvFormatInt): New primitive, with logic taken from old Integer.toString code. (Integer::valueOf): Use _Jv_FormatInt. * java/lang/Integer.java (toString): Just use call String.valueOf. * java/lang/Long.java (toString): Fix typo in comment. * java/lang/String.java (valueOf(int)): Make native. * java/lang/StringBuffer.java (append(int)): Make native. * java/lang/natStringBuffer.cc: New file, for append(jint). * Makefile.am (ant_source_files): Add java/lang/natStringBuffer.cc. From-SVN: r42419
This commit is contained in:
parent
f5d6a24c2e
commit
ef0a7b49a9
@ -1,3 +1,16 @@
|
||||
2001-05-21 Per Bothner <per@bothner.com>
|
||||
|
||||
* gcj/javaprims.h (_Jv_FormatInt): New declaration.
|
||||
* java/lang/natString.cc (_JvFormatInt): New primitive, with logic
|
||||
taken from old Integer.toString code.
|
||||
(Integer::valueOf): Use _Jv_FormatInt.
|
||||
* java/lang/Integer.java (toString): Just use call String.valueOf.
|
||||
* java/lang/Long.java (toString): Fix typo in comment.
|
||||
* java/lang/String.java (valueOf(int)): Make native.
|
||||
* java/lang/StringBuffer.java (append(int)): Make native.
|
||||
* java/lang/natStringBuffer.cc: New file, for append(jint).
|
||||
* Makefile.am (ant_source_files): Add java/lang/natStringBuffer.cc.
|
||||
|
||||
2001-05-21 Tom Tromey <tromey@redhat.com>
|
||||
|
||||
* gnu/gcj/runtime/VMClassLoader.java (VMClassLoader): Now public.
|
||||
|
@ -1324,6 +1324,7 @@ java/lang/natMath.cc \
|
||||
java/lang/natObject.cc \
|
||||
java/lang/natRuntime.cc \
|
||||
java/lang/natString.cc \
|
||||
java/lang/natStringBuffer.cc \
|
||||
java/lang/natSystem.cc \
|
||||
java/lang/natThread.cc \
|
||||
java/lang/natThrowable.cc \
|
||||
|
@ -1068,6 +1068,7 @@ java/lang/natMath.cc \
|
||||
java/lang/natObject.cc \
|
||||
java/lang/natRuntime.cc \
|
||||
java/lang/natString.cc \
|
||||
java/lang/natStringBuffer.cc \
|
||||
java/lang/natSystem.cc \
|
||||
java/lang/natThread.cc \
|
||||
java/lang/natThrowable.cc \
|
||||
@ -1224,7 +1225,7 @@ java/io/natObjectOutputStream.lo java/lang/natCharacter.lo \
|
||||
java/lang/natClass.lo java/lang/natClassLoader.lo \
|
||||
java/lang/natConcreteProcess.lo java/lang/natDouble.lo \
|
||||
java/lang/natFloat.lo java/lang/natMath.lo java/lang/natObject.lo \
|
||||
java/lang/natRuntime.lo java/lang/natString.lo java/lang/natSystem.lo \
|
||||
java/lang/natRuntime.lo java/lang/natString.lo java/lang/natStringBuffer.lo java/lang/natSystem.lo \
|
||||
java/lang/natThread.lo java/lang/natThrowable.lo \
|
||||
java/lang/reflect/natArray.lo java/lang/reflect/natConstructor.lo \
|
||||
java/lang/reflect/natField.lo java/lang/reflect/natMethod.lo \
|
||||
@ -1632,7 +1633,7 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \
|
||||
.deps/java/lang/natClassLoader.P .deps/java/lang/natConcreteProcess.P \
|
||||
.deps/java/lang/natDouble.P .deps/java/lang/natFloat.P \
|
||||
.deps/java/lang/natMath.P .deps/java/lang/natObject.P \
|
||||
.deps/java/lang/natRuntime.P .deps/java/lang/natString.P \
|
||||
.deps/java/lang/natRuntime.P .deps/java/lang/natString.P .deps/java/lang/natStringBuffer.P \
|
||||
.deps/java/lang/natSystem.P .deps/java/lang/natThread.P \
|
||||
.deps/java/lang/natThrowable.P .deps/java/lang/ref/PhantomReference.P \
|
||||
.deps/java/lang/ref/Reference.P .deps/java/lang/ref/ReferenceQueue.P \
|
||||
|
@ -371,6 +371,7 @@ extern "C" jboolean _Jv_IsInstanceOf(jobject, jclass);
|
||||
extern "C" jstring _Jv_AllocString(jsize) __attribute__((__malloc__));
|
||||
extern "C" jstring _Jv_NewString (const jchar*, jsize)
|
||||
__attribute__((__malloc__));
|
||||
extern jint _Jv_FormatInt (jchar* bufend, jint num);
|
||||
extern "C" jchar* _Jv_GetStringChars (jstring str);
|
||||
extern "C" jint _Jv_MonitorEnter (jobject);
|
||||
extern "C" jint _Jv_MonitorExit (jobject);
|
||||
|
@ -267,35 +267,7 @@ public final class Integer extends Number implements Comparable
|
||||
|
||||
public static String toString(int num)
|
||||
{
|
||||
// Use an arrary large enough for "-2147483648"; i.e. 11 chars.
|
||||
char[] buffer = new char[11];
|
||||
int i = 11;
|
||||
boolean isNeg;
|
||||
if (num < 0)
|
||||
{
|
||||
isNeg = true;
|
||||
num = -(num);
|
||||
if (num < 0)
|
||||
{
|
||||
// Must be MIN_VALUE, so handle this special case.
|
||||
buffer[--i] = '8';
|
||||
num = 214748364;
|
||||
}
|
||||
}
|
||||
else
|
||||
isNeg = false;
|
||||
|
||||
do
|
||||
{
|
||||
buffer[--i] = (char) ((int) '0' + (num % 10));
|
||||
num /= 10;
|
||||
}
|
||||
while (num > 0);
|
||||
|
||||
if (isNeg)
|
||||
buffer[--i] = '-';
|
||||
|
||||
return String.valueOf(buffer, i, 11-i);
|
||||
return String.valueOf (num);
|
||||
}
|
||||
|
||||
public static String toString(int num, int radix)
|
||||
|
@ -273,7 +273,7 @@ public final class Long extends Number implements Comparable
|
||||
if (num <= Integer.MAX_VALUE && num >= Integer.MIN_VALUE)
|
||||
return Integer.toString((int) num);
|
||||
|
||||
// Use an arrary large enough for "-9223372036854775808"; i.e. 11 chars.
|
||||
// Use an array large enough for "-9223372036854775808"; i.e. 20 chars.
|
||||
char[] buffer = new char[20];
|
||||
int i = 20;
|
||||
boolean isNeg;
|
||||
|
@ -319,10 +319,7 @@ public final class String implements Serializable, Comparable
|
||||
|
||||
public static native String valueOf (char c);
|
||||
|
||||
public static String valueOf (int i)
|
||||
{
|
||||
return Integer.toString(i);
|
||||
}
|
||||
public static native String valueOf (int i);
|
||||
|
||||
public static String valueOf (long l)
|
||||
{
|
||||
|
@ -89,10 +89,7 @@ public final class StringBuffer implements Serializable
|
||||
* @return this <code>StringBuffer</code>.
|
||||
* @see java.lang.String#valueOf(int)
|
||||
*/
|
||||
public StringBuffer append (int inum)
|
||||
{
|
||||
return append (String.valueOf(inum));
|
||||
}
|
||||
public native StringBuffer append (int inum);
|
||||
|
||||
/** Append the <code>String</code> value of the argument to this <code>StringBuffer</code>.
|
||||
* Uses <code>String.valueOf()</code> to convert to
|
||||
|
@ -341,6 +341,52 @@ _Jv_GetStringUTFRegion (jstring str, jsize start, jsize len, char *buf)
|
||||
return dptr - buf;
|
||||
}
|
||||
|
||||
/* Put printed (decimal) representation of NUM in a buffer.
|
||||
BUFEND marks the end of the buffer, which must be at least 11 jchars long.
|
||||
Returns the COUNT of jchars written. The result is in
|
||||
(BUFEND - COUNT) (inclusive) upto (BUFEND) (exclusive). */
|
||||
|
||||
jint
|
||||
_Jv_FormatInt (jchar* bufend, jint num)
|
||||
{
|
||||
register jchar* ptr = bufend;
|
||||
jboolean isNeg;
|
||||
if (num < 0)
|
||||
{
|
||||
isNeg = true;
|
||||
num = -(num);
|
||||
if (num < 0)
|
||||
{
|
||||
// Must be MIN_VALUE, so handle this special case.
|
||||
// FIXME use 'unsigned jint' for num.
|
||||
*--ptr = '8';
|
||||
num = 214748364;
|
||||
}
|
||||
}
|
||||
else
|
||||
isNeg = false;
|
||||
|
||||
do
|
||||
{
|
||||
*--ptr = (jchar) ((int) '0' + (num % 10));
|
||||
num /= 10;
|
||||
}
|
||||
while (num > 0);
|
||||
|
||||
if (isNeg)
|
||||
*--ptr = '-';
|
||||
return bufend - ptr;
|
||||
}
|
||||
|
||||
jstring
|
||||
java::lang::String::valueOf (jint num)
|
||||
{
|
||||
// Use an array large enough for "-2147483648"; i.e. 11 chars.
|
||||
jchar buffer[11];
|
||||
int i = _Jv_FormatInt (buffer+11, num);
|
||||
return _Jv_NewString (buffer+11-i, i);
|
||||
}
|
||||
|
||||
jstring
|
||||
_Jv_AllocString(jsize len)
|
||||
{
|
||||
|
30
libjava/java/lang/natStringBuffer.cc
Normal file
30
libjava/java/lang/natStringBuffer.cc
Normal file
@ -0,0 +1,30 @@
|
||||
// natStringBuffer.cc - Implementation of java.lang.StringBuffer native methods.
|
||||
|
||||
/* Copyright (C) 2001 Free Software Foundation
|
||||
|
||||
This file is part of libgcj.
|
||||
|
||||
This software is copyrighted work licensed under the terms of the
|
||||
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
||||
details. */
|
||||
|
||||
#include <config.h>
|
||||
#include <gcj/cni.h>
|
||||
#include <java/lang/StringBuffer.h>
|
||||
|
||||
java::lang::StringBuffer*
|
||||
java::lang::StringBuffer::append (jint num)
|
||||
{
|
||||
// Use an array large enough for "-2147483648"; i.e. 11 chars.
|
||||
jchar buffer[11];
|
||||
int i = _Jv_FormatInt (buffer+11, num);
|
||||
JvSynchronize dummy (this);
|
||||
jint needed = count + i;
|
||||
ensureCapacity_unsynchronized (needed);
|
||||
jchar* dst = elements (value) + count;
|
||||
jchar* src = buffer+11-i;
|
||||
while (--i >= 0)
|
||||
*dst++ = *src++;
|
||||
count = needed;
|
||||
return this;
|
||||
}
|
Loading…
Reference in New Issue
Block a user