summaryrefslogtreecommitdiff
path: root/src/json/ext/OptionsReader.java
diff options
context:
space:
mode:
authorDaniel Luz <dev@mernen.com>2010-08-07 05:45:54 -0300
committerDaniel Luz <dev@mernen.com>2010-08-07 05:47:02 -0300
commit56f281e91ea596b46b48b80df57445fee6710590 (patch)
tree9a5be6d699d0350d5b2d609fdd5919b8728f0655 /src/json/ext/OptionsReader.java
parent2c448b41cba11e4acd6492e17618ddf8d48f5e0c (diff)
downloadjson-56f281e91ea596b46b48b80df57445fee6710590.tar.gz
Java: made the OptionsReader instantiation less silly
Diffstat (limited to 'src/json/ext/OptionsReader.java')
-rw-r--r--src/json/ext/OptionsReader.java21
1 files changed, 8 insertions, 13 deletions
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);
}