Skip to content

Instantly share code, notes, and snippets.

@enebo
Created May 21, 2020 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enebo/8fa2c17a3384a962da7b24b0168c40d2 to your computer and use it in GitHub Desktop.
Save enebo/8fa2c17a3384a962da7b24b0168c40d2 to your computer and use it in GitHub Desktop.
diff --git a/core/src/main/java/org/jruby/util/ConvertBytes.java b/core/src/main/java/org/jruby/util/ConvertBytes.java
index 644d46da13..a2d4a8709d 100644
--- a/core/src/main/java/org/jruby/util/ConvertBytes.java
+++ b/core/src/main/java/org/jruby/util/ConvertBytes.java
@@ -176,10 +176,13 @@ public class ConvertBytes {
if (neg) newSize++;
string.resize(newSize);
ByteList byteList = string.getByteList();
+ byte[] bytes = byteList.getUnsafeBytes();
+ int beg = byteList.begin();
- do {
- byteList.set(--newSize, LOWER_DIGITS[(int) (i % 10)]);
- } while ((i /= 10) > 0);
+ for (int n = newSize - 1; i > 0 && n >= newSize - len; n--) {
+ bytes[beg + n] = LOWER_DIGITS[(int) (i % 10)];
+ i /= 10;
+ }
if (neg) byteList.set(--newSize, '-');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment