Fixes System.arraycopy behavior when src == dest

This commit is contained in:
konsoletyper 2014-03-22 11:32:39 +04:00
parent 6c599c2886
commit 8e99b4589e

View File

@ -74,9 +74,17 @@ public class SystemNativeGenerator implements Generator, DependencyPlugin {
String dest = context.getParameterName(3);
String destPos = context.getParameterName(4);
String length = context.getParameterName(5);
writer.append("if (" + src + " !== " + dest + " || " + destPos + " < " + srcPos + ") {").indent().newLine();
writer.append("for (var i = 0; i < " + length + "; i = (i + 1) | 0) {").indent().softNewLine();
writer.append(dest + ".data[" + destPos + "++] = " + src + ".data[" + srcPos + "++];").softNewLine();
writer.outdent().append("}").softNewLine();
writer.outdent().append("} else {").indent().softNewLine();
writer.append(srcPos + " = (" + srcPos + " + " + length + ") | 0;").softNewLine();
writer.append(destPos + " = (" + destPos + " + " + length + ") | 0;").softNewLine();
writer.append("for (var i = 0; i < " + length + "; i = (i + 1) | 0) {").indent().softNewLine();
writer.append(dest + ".data[--" + destPos + "] = " + src + ".data[--" + srcPos + "];").softNewLine();
writer.outdent().append("}").softNewLine();
writer.outdent().append("}").softNewLine();
}
private void generateCurrentTimeMillis(SourceWriter writer) throws IOException {