From 4bf6dac18021e1928984fe1533a88d5a65860405 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Wed, 18 Jan 2023 23:23:07 -0600 Subject: Minor tweaks and cleanup in emitter --- ext/java/org/jruby/ext/psych/PsychEmitter.java | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/ext/java/org/jruby/ext/psych/PsychEmitter.java b/ext/java/org/jruby/ext/psych/PsychEmitter.java index baaca4a..4df7989 100644 --- a/ext/java/org/jruby/ext/psych/PsychEmitter.java +++ b/ext/java/org/jruby/ext/psych/PsychEmitter.java @@ -118,17 +118,14 @@ public class PsychEmitter extends RubyObject { initEmitter(context, encoding); - StreamStartEvent event = new StreamStartEvent(NULL_MARK, NULL_MARK); - - emit(context, event); + emit(context, NULL_STREAM_START_EVENT); return this; } @JRubyMethod public IRubyObject end_stream(ThreadContext context) { - StreamEndEvent event = new StreamEndEvent(NULL_MARK, NULL_MARK); - emit(context, event); + emit(context, NULL_STREAM_START_EVENT); return this; } @@ -368,16 +365,16 @@ public class PsychEmitter extends RubyObject { return dumpSettingsBuilder.build(); } - private String exportToUTF8(ThreadContext context, IRubyObject tag, RubyClass stringClass) { - if (tag.isNil()) { + private String exportToUTF8(ThreadContext context, IRubyObject maybeString, RubyClass stringClass) { + if (maybeString.isNil()) { return null; } - RubyString tagStr; + RubyString string; - TypeConverter.checkType(context, tag, stringClass); - tagStr = (RubyString) tag; - ByteList bytes = tagStr.getByteList(); + TypeConverter.checkType(context, maybeString, stringClass); + string = (RubyString) maybeString; + ByteList bytes = string.getByteList(); return RubyEncoding.decodeUTF8(bytes.unsafeBytes(), bytes.begin(), bytes.realSize()); } @@ -388,6 +385,7 @@ public class PsychEmitter extends RubyObject { IRubyObject io; private static final Optional NULL_MARK = Optional.empty(); + private static final StreamStartEvent NULL_STREAM_START_EVENT = new StreamStartEvent(NULL_MARK, NULL_MARK); // Map style constants from Psych values (ANY = 0 ... FOLDED = 5) // to SnakeYaml values; see psych/nodes/scalar.rb. -- cgit v1.2.1