summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2011-12-20 23:05:15 +0100
committerFlorian Frank <flori@ping.de>2011-12-20 23:05:15 +0100
commitaa7feb07b68e13ce2e024669873a8a6a89f304dc (patch)
tree6c11497c2c6e417cbb56705fb96c7366e6fc58fb /java
parentdec1286737e8d9c3d61ec9f6726a88d65592f48e (diff)
downloadjson-aa7feb07b68e13ce2e024669873a8a6a89f304dc.tar.gz
Support duck typed ruby array in JRuby as well
Diffstat (limited to 'java')
-rw-r--r--java/src/json/ext/Parser.java16
-rw-r--r--java/src/json/ext/Parser.rl16
2 files changed, 16 insertions, 16 deletions
diff --git a/java/src/json/ext/Parser.java b/java/src/json/ext/Parser.java
index 1ff25a6..579b047 100644
--- a/java/src/json/ext/Parser.java
+++ b/java/src/json/ext/Parser.java
@@ -1608,12 +1608,12 @@ static final int JSON_array_en_main = 1;
// this is guaranteed to be a RubyArray due to the earlier
// allocator test at OptionsReader#getClass
- RubyArray result;
- if (parser.arrayClass != getRuntime().getArray()) {
- result = (RubyArray)parser.arrayClass.newInstance(context,
- IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
- } else {
+ IRubyObject result;
+ if (parser.arrayClass == getRuntime().getArray()) {
result = RubyArray.newArray(getRuntime());
+ } else {
+ result = parser.arrayClass.newInstance(context,
+ IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
}
@@ -1712,10 +1712,10 @@ case 1:
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
} else {
- if (parser.arrayClass != getRuntime().getArray()) {
- result.callMethod(context, "<<", res.result);
+ if (parser.arrayClass == getRuntime().getArray()) {
+ ((RubyArray)result).append(res.result);
} else {
- result.append(res.result);
+ result.callMethod(context, "<<", res.result);
}
{p = (( res.p))-1;}
}
diff --git a/java/src/json/ext/Parser.rl b/java/src/json/ext/Parser.rl
index bb6a38f..fd759f5 100644
--- a/java/src/json/ext/Parser.rl
+++ b/java/src/json/ext/Parser.rl
@@ -663,10 +663,10 @@ public class Parser extends RubyObject {
fhold;
fbreak;
} else {
- if (parser.arrayClass != getRuntime().getArray()) {
- result.callMethod(context, "<<", res.result);
+ if (parser.arrayClass == getRuntime().getArray()) {
+ ((RubyArray)result).append(res.result);
} else {
- result.append(res.result);
+ result.callMethod(context, "<<", res.result);
}
fexec res.p;
}
@@ -700,12 +700,12 @@ public class Parser extends RubyObject {
// this is guaranteed to be a RubyArray due to the earlier
// allocator test at OptionsReader#getClass
- RubyArray result;
- if (parser.arrayClass != getRuntime().getArray()) {
- result = (RubyArray)parser.arrayClass.newInstance(context,
- IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
- } else {
+ IRubyObject result;
+ if (parser.arrayClass == getRuntime().getArray()) {
result = RubyArray.newArray(getRuntime());
+ } else {
+ result = parser.arrayClass.newInstance(context,
+ IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
}
%% write init;