Skip to content

Commit 84105bf

Browse files
committed
Explicitly pass lenght to replace methods
1 parent 3283077 commit 84105bf

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/CodecsModuleBuiltins.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private static boolean backslashreplace(TruffleEncoder encoder) {
182182
}
183183
i += Character.charCount(ch);
184184
}
185-
encoder.replace(sb.toString(), p.length());
185+
encoder.replace(p.length(), sb.toString());
186186
return true;
187187
}
188188

@@ -204,7 +204,7 @@ private static boolean surrogatepass(TruffleEncoder encoder) {
204204
replacement[outp++] = (byte) (0x80 | (ch & 0x3f));
205205
i += Character.charCount(ch);
206206
}
207-
encoder.replace(replacement, encoder.getErrorLenght());
207+
encoder.replace(encoder.getErrorLenght(), replacement, 0, outp);
208208
return true;
209209
}
210210
return false;
@@ -280,7 +280,7 @@ private static boolean backslashreplace(TruffleDecoder decoder) {
280280
replacement[outp++] = (char) buf[2];
281281
replacement[outp++] = (char) buf[3];
282282
}
283-
decoder.replace(replacement, p.length);
283+
decoder.replace(p.length, replacement, 0, outp);
284284
return true;
285285
}
286286

@@ -293,7 +293,7 @@ private static boolean surrogatepass(TruffleDecoder decoder) {
293293
if ((p[0] & 0xf0) == 0xe0 && (p[1] & 0xc0) == 0x80 && (p[2] & 0xc0) == 0x80) {
294294
int codePoint = ((p[0] & 0x0f) << 12) + ((p[1] & 0x3f) << 6) + (p[2] & 0x3f);
295295
if (0xD800 <= codePoint && codePoint <= 0xDFFF) {
296-
decoder.replace(Character.toChars(codePoint), 3);
296+
decoder.replace(3, Character.toChars(codePoint));
297297
return true;
298298
}
299299
}
@@ -646,16 +646,16 @@ public char[] getInputChars(int num) {
646646
}
647647

648648
@TruffleBoundary
649-
public void replace(byte[] replacement, int skipInput) {
649+
public void replace(int skipInput, byte[] replacement, int offset, int length) {
650650
while (outputBuffer.remaining() < replacement.length) {
651651
grow();
652652
}
653-
outputBuffer.put(replacement);
653+
outputBuffer.put(replacement, offset, length);
654654
inputBuffer.position(inputBuffer.position() + skipInput);
655655
}
656656

657657
@TruffleBoundary
658-
public void replace(String replacement, int skipInput) {
658+
public void replace(int skipInput, String replacement) {
659659
inputBuffer.position(inputBuffer.position() + skipInput);
660660
CharBuffer newBuffer = CharBuffer.allocate(inputBuffer.remaining() + replacement.length());
661661
newBuffer.put(replacement);
@@ -752,12 +752,16 @@ public int getErrorLenght() {
752752
return coderResult.length();
753753
}
754754

755+
public void replace(int skipInput, char[] chars) {
756+
replace(skipInput, chars, 0, chars.length);
757+
}
758+
755759
@TruffleBoundary
756-
public void replace(char[] chars, int skipInput) {
760+
public void replace(int skipInput, char[] chars, int offset, int lenght) {
757761
while (outputBuffer.remaining() < chars.length) {
758762
grow();
759763
}
760-
outputBuffer.put(chars);
764+
outputBuffer.put(chars, offset, lenght);
761765
inputBuffer.position(inputBuffer.position() + skipInput);
762766
}
763767

0 commit comments

Comments
 (0)