* 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
+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.
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 \
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 \
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 \
.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 \
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);
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)
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;
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)
{
* @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
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)
{
--- /dev/null
+// 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;
+}