Skip to content

Commit 6c53669

Browse files
committed
Use our thread-local UTF8 decoder to avoid constructing any.
1 parent f8782ac commit 6c53669

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

core/src/main/java/org/jruby/lexer/yacc/RubyLexer.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.joni.Option;
4747
import org.joni.Regex;
4848
import org.jruby.Ruby;
49+
import org.jruby.RubyEncoding;
4950
import org.jruby.RubyRegexp;
5051
import org.jruby.ast.BackRefNode;
5152
import org.jruby.ast.BignumNode;
@@ -314,7 +315,13 @@ public String createTokenString() {
314315
// FIXME: We should be able to move some faster non-exception cache using Encoding.isDefined
315316
try {
316317
charset = current_enc.getCharset();
317-
if (charset != null) return new String(bytes, begin + tokp, lex_p - tokp, charset);
318+
if (charset != null) {
319+
if (charset == RubyEncoding.UTF8) {
320+
return RubyEncoding.decodeUTF8(bytes, begin + tokp, lex_p - tokp);
321+
} else {
322+
return new String(bytes, begin + tokp, lex_p - tokp, charset);
323+
}
324+
}
318325
} catch (UnsupportedCharsetException e) {}
319326

320327

0 commit comments

Comments
 (0)