diff options
author | Daniel Luz <dev@mernen.com> | 2010-08-07 05:45:54 -0300 |
---|---|---|
committer | Daniel Luz <dev@mernen.com> | 2010-08-07 05:47:02 -0300 |
commit | 56f281e91ea596b46b48b80df57445fee6710590 (patch) | |
tree | 9a5be6d699d0350d5b2d609fdd5919b8728f0655 | |
parent | 2c448b41cba11e4acd6492e17618ddf8d48f5e0c (diff) | |
download | json-56f281e91ea596b46b48b80df57445fee6710590.tar.gz |
Java: made the OptionsReader instantiation less silly
-rw-r--r-- | src/json/ext/GeneratorState.java | 2 | ||||
-rw-r--r-- | src/json/ext/OptionsReader.java | 21 |
2 files changed, 9 insertions, 14 deletions
diff --git a/src/json/ext/GeneratorState.java b/src/json/ext/GeneratorState.java index 1f24055..63263e8 100644 --- a/src/json/ext/GeneratorState.java +++ b/src/json/ext/GeneratorState.java @@ -399,7 +399,7 @@ public class GeneratorState extends RubyObject { */ @JRubyMethod public IRubyObject configure(ThreadContext context, IRubyObject vOpts) { - OptionsReader opts = OptionsReader.withStrings(context, vOpts); + OptionsReader opts = new OptionsReader(context, vOpts); ByteList indent = opts.getString("indent"); if (indent != null) this.indent = indent; diff --git a/src/json/ext/OptionsReader.java b/src/json/ext/OptionsReader.java index 29de188..3bc8d5f 100644 --- a/src/json/ext/OptionsReader.java +++ b/src/json/ext/OptionsReader.java @@ -18,14 +18,12 @@ import org.jruby.util.ByteList; final class OptionsReader { private final ThreadContext context; private final Ruby runtime; - private final RuntimeInfo info; private final RubyHash opts; + private RuntimeInfo info; - private OptionsReader(ThreadContext context, Ruby runtime, - RuntimeInfo info, IRubyObject vOpts) { + OptionsReader(ThreadContext context, IRubyObject vOpts) { this.context = context; - this.runtime = runtime; - this.info = info; + this.runtime = context.getRuntime(); if (vOpts == null || vOpts.isNil()) { opts = null; @@ -36,14 +34,10 @@ final class OptionsReader { } } - OptionsReader(ThreadContext context, IRubyObject vOpts) { - this(context, context.getRuntime(), null, vOpts); - } - - static OptionsReader withStrings(ThreadContext context, IRubyObject vOpts) { - Ruby runtime = context.getRuntime(); - return new OptionsReader(context, runtime, - RuntimeInfo.forRuntime(runtime), vOpts); + private RuntimeInfo getRuntimeInfo() { + if (info != null) return info; + info = RuntimeInfo.forRuntime(runtime); + return info; } /** @@ -84,6 +78,7 @@ final class OptionsReader { if (value == null || !value.isTrue()) return null; RubyString str = value.convertToString(); + RuntimeInfo info = getRuntimeInfo(); if (info.encodingsSupported() && str.encoding(context) != info.utf8) { str = (RubyString)str.encode(context, info.utf8); } |