Merge branch 'master' of oss.readytalk.com:/var/local/git/avian into openjdk

This commit is contained in:
Joel Dice 2010-09-10 15:58:43 -06:00
commit 64100d17c7
4 changed files with 66 additions and 61 deletions

View File

@ -31,6 +31,7 @@ public class PrintStream extends OutputStream {
public synchronized void print(String s) { public synchronized void print(String s) {
try { try {
out.write(s.getBytes()); out.write(s.getBytes());
if (autoFlush) flush();
} catch (IOException e) { } } catch (IOException e) { }
} }

View File

@ -115,23 +115,34 @@ public class Pattern {
List<CharSequence> list = new LinkedList(); List<CharSequence> list = new LinkedList();
int index = 0; int index = 0;
int trailing = 0; int trailing = 0;
while (index < input.length() && list.size() < limit) { int patternLength = pattern.length();
int i = indexOf(input, pattern, index); while (index < input.length() && list.size() < limit - 1) {
int i;
if (patternLength == 0) {
if (list.size() == 0) {
i = 0;
} else {
i = index + 1;
}
} else {
i = indexOf(input, pattern, index);
}
if (i >= 0) { if (i >= 0) {
if (i == index) { if (patternLength != 0 && i == index) {
++ trailing; ++ trailing;
} else { } else {
trailing = 0; trailing = 0;
} }
list.add(input.subSequence(index, i)); list.add(input.subSequence(index, i));
index = i + pattern.length(); index = i + patternLength;
} else { } else {
break; break;
} }
} }
if (strip && index == input.length()) { if (strip && index > 0 && index == input.length()) {
++ trailing; ++ trailing;
} else { } else {
trailing = 0; trailing = 0;

View File

@ -1677,62 +1677,6 @@ jumpC(Context* c, unsigned size UNUSED, Assembler::Constant* target)
emit(c, b(0)); emit(c, b(0));
} }
void
jumpIfEqualC(Context* c, unsigned size UNUSED, Assembler::Constant* target)
{
assert(c, size == BytesPerWord);
appendOffsetTask(c, target->value, offset(c), true);
emit(c, beq(0));
}
void
jumpIfNotEqualC(Context* c, unsigned size UNUSED, Assembler::Constant* target)
{
assert(c, size == BytesPerWord);
appendOffsetTask(c, target->value, offset(c), true);
emit(c, bne(0));
}
void
jumpIfGreaterC(Context* c, unsigned size UNUSED, Assembler::Constant* target)
{
assert(c, size == BytesPerWord);
appendOffsetTask(c, target->value, offset(c), true);
emit(c, bgt(0));
}
void
jumpIfGreaterOrEqualC(Context* c, unsigned size UNUSED,
Assembler::Constant* target)
{
assert(c, size == BytesPerWord);
appendOffsetTask(c, target->value, offset(c), true);
emit(c, bge(0));
}
void
jumpIfLessC(Context* c, unsigned size UNUSED, Assembler::Constant* target)
{
assert(c, size == BytesPerWord);
appendOffsetTask(c, target->value, offset(c), true);
emit(c, blt(0));
}
void
jumpIfLessOrEqualC(Context* c, unsigned size UNUSED,
Assembler::Constant* target)
{
assert(c, size == BytesPerWord);
appendOffsetTask(c, target->value, offset(c), true);
emit(c, ble(0));
}
void void
return_(Context* c) return_(Context* c)
{ {
@ -2198,6 +2142,12 @@ class MyAssembler: public Assembler {
} }
virtual void saveFrame(unsigned stackOffset, unsigned) { virtual void saveFrame(unsigned stackOffset, unsigned) {
Register returnAddress(0);
emit(&c, mflr(returnAddress.low));
Memory returnAddressDst(StackRegister, 8);
moveRM(&c, BytesPerWord, &returnAddress, BytesPerWord, &returnAddressDst);
Register stack(StackRegister); Register stack(StackRegister);
Memory stackDst(ThreadRegister, stackOffset); Memory stackDst(ThreadRegister, stackOffset);
moveRM(&c, BytesPerWord, &stack, BytesPerWord, &stackDst); moveRM(&c, BytesPerWord, &stack, BytesPerWord, &stackDst);

View File

@ -3,6 +3,24 @@ public class Strings {
if (! v) throw new RuntimeException(); if (! v) throw new RuntimeException();
} }
private static boolean equal(Object a, Object b) {
return a == b || (a != null && a.equals(b));
}
private static boolean arraysEqual(Object[] a, Object[] b) {
if (a.length != b.length) {
return false;
}
for (int i = 0; i < a.length; ++i) {
if (! equal(a[i], b[i])) {
return false;
}
}
return true;
}
public static void main(String[] args) { public static void main(String[] args) {
expect(new String(new byte[] { 99, 111, 109, 46, 101, 99, 111, 118, 97, expect(new String(new byte[] { 99, 111, 109, 46, 101, 99, 111, 118, 97,
116, 101, 46, 110, 97, 116, 46, 98, 117, 116, 101, 46, 110, 97, 116, 46, 98, 117,
@ -13,6 +31,31 @@ public class Strings {
expect(months.split("\u00ae").length == 3); expect(months.split("\u00ae").length == 3);
expect(months.replaceAll("\u00ae", ".").equals("Jan.Feb.Mar.")); expect(months.replaceAll("\u00ae", ".").equals("Jan.Feb.Mar."));
expect(arraysEqual
("xyz".split("", 0), new String[] { "", "x", "y", "z" }));
expect(arraysEqual
("xyz".split("", 1), new String[] { "xyz" }));
expect(arraysEqual
("xyz".split("", 2), new String[] { "", "xyz" }));
expect(arraysEqual
("xyz".split("", 3), new String[] { "", "x", "yz" }));
expect(arraysEqual
("xyz".split("", 4), new String[] { "", "x", "y", "z" }));
expect(arraysEqual
("xyz".split("", 5), new String[] { "", "x", "y", "z", "" }));
expect(arraysEqual
("xyz".split("", 6), new String[] { "", "x", "y", "z", "" }));
expect(arraysEqual
("xyz".split("", -1), new String[] { "", "x", "y", "z", "" }));
expect(arraysEqual("".split("xyz", 0), new String[] { "" }));
expect(arraysEqual("".split("xyz", 1), new String[] { "" }));
expect(arraysEqual("".split("xyz", -1), new String[] { "" }));
expect(arraysEqual("".split("", 0), new String[] { "" }));
expect(arraysEqual("".split("", 1), new String[] { "" }));
expect(arraysEqual("".split("", -1), new String[] { "" }));
expect("foo_foofoo__foo".replaceAll("_", "__") expect("foo_foofoo__foo".replaceAll("_", "__")
.equals("foo__foofoo____foo")); .equals("foo__foofoo____foo"));