summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Oliver Nutter <headius@headius.com>2023-01-18 23:23:07 -0600
committerCharles Oliver Nutter <headius@headius.com>2023-01-18 23:23:07 -0600
commit4bf6dac18021e1928984fe1533a88d5a65860405 (patch)
tree580305895d242982d60361658315910fe831f385
parentc662354eecbae162b9287b8b566b432421414f96 (diff)
downloadpsych-4bf6dac18021e1928984fe1533a88d5a65860405.tar.gz
Minor tweaks and cleanup in emitter
-rw-r--r--ext/java/org/jruby/ext/psych/PsychEmitter.java20
1 files 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<Mark> 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.