From 956106f518ca04c51c432021a2a4064a71e0798a Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 29 Oct 2007 15:40:05 -0600 Subject: [PATCH] implement StringBuilder.delete() more efficiently --- classpath/java/lang/StringBuilder.java | 45 ++++++++++++++------------ makefile | 2 +- src/interpret.cpp | 10 ++++++ 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/classpath/java/lang/StringBuilder.java b/classpath/java/lang/StringBuilder.java index 02e8510c52..917d4f5090 100644 --- a/classpath/java/lang/StringBuilder.java +++ b/classpath/java/lang/StringBuilder.java @@ -149,16 +149,11 @@ public class StringBuilder { } public StringBuilder delete(int start, int end) { - int numChars = end - start; // Do not delete end itself - while (numChars > 0) { - deleteCharAt(start); - numChars--; + if (start >= end) { + return this; } - return this; - } - public StringBuilder deleteCharAt(int i) { - if (i < 0 || i >= length) { + if (start < 0 || end > length) { throw new IndexOutOfBoundsException(); } @@ -168,32 +163,40 @@ public class StringBuilder { -- length; Cell p = null; for (Cell c = chain; c != null; c = c.next) { - int start = index - c.value.length(); - index = start; + int e = index; + int s = index - c.value.length(); + index = s; - if (i >= start) { - if (c.value.length() == 1) { + if (end >= e) { + if (start <= s) { if (p == null) { chain = c.next; } else { p.next = c.next; - } - } else if (i == start) { - c.value = c.value.substring(1); - } else if (i == start + c.value.length() - 1) { - c.value = c.value.substring(0, c.value.length() - 1); + } + } else { + c.value = c.value.substring(0, start - s); + break; + } + } else { + if (start <= s) { + c.value = c.value.substring(end - s, e - s); } else { String v = c.value; - c.value = v.substring(i - start + 1, v.length()); - c.next = new Cell(v.substring(0, i - start), c.next); - } - break; + c.value = v.substring(end - s, e - s); + c.next = new Cell(v.substring(0, start - s), c.next); + break; + } } } return this; } + public StringBuilder deleteCharAt(int i) { + return delete(i, i + 1); + } + public StringBuilder replace(int start, int end, String str) { delete(start, end); insert(start, str); diff --git a/makefile b/makefile index 405454ece6..8a400218da 100644 --- a/makefile +++ b/makefile @@ -112,7 +112,7 @@ ifeq ($(mode),stress-major) cflags += -O0 -g3 -DVM_STRESS -DVM_STRESS_MAJOR endif ifeq ($(mode),fast) - cflags += -O3 -DNDEBUG + cflags += -O3 -g3 -DNDEBUG strip = strip show-size = ls -l endif diff --git a/src/interpret.cpp b/src/interpret.cpp index 287d3d5bb0..dd95cc0885 100644 --- a/src/interpret.cpp +++ b/src/interpret.cpp @@ -529,6 +529,16 @@ invokeNative(Thread* t, object method) &byteArrayBody(t, methodName(t, method), 0)); } +// if (strcmp(reinterpret_cast +// (&byteArrayBody(t, className(t, methodClass(t, method)), 0)), +// "org/eclipse/swt/internal/C") == 0 +// and strcmp(reinterpret_cast +// (&byteArrayBody(t, methodName(t, method), 0)), +// "memmove") == 0) +// { +// asm("int3"); +// } + { ENTER(t, Thread::IdleState); result = t->m->system->call