Skip to content

Instantly share code, notes, and snippets.

@bbrowning
Created December 16, 2014 00:40
Show Gist options
  • Save bbrowning/707abba9cf9548c7de31 to your computer and use it in GitHub Desktop.
Save bbrowning/707abba9cf9548c7de31 to your computer and use it in GitHub Desktop.
require 'benchmark'
require 'json/ext'
NUM_THREADS = 40
NUM_PARSES = 20_000
def run_test(json)
puts Benchmark.measure {
threads = NUM_THREADS.times.map do
Thread.new do
NUM_PARSES.times do
JSON.parse(json)
end
end
end
threads.each(&:join)
}
end
run_test <<-EOS
[
{
"_id": "548f596dd33df01c86944622",
"index": 0,
"guid": "4a4fad7a-1c4e-4048-8c42-b10cf0d825a8",
"isActive": false,
"balance": "$1,529.59",
"picture": "http://placehold.it/32x32",
"age": 23,
"eyeColor": "brown",
"name": "Stuart Delacruz",
"gender": "male",
"company": "OLYMPIX",
"email": "stuartdelacruz@olympix.com",
"phone": "+1 (861) 442-2558",
"address": "714 Grand Street, Carbonville, Vermont, 3847",
"about": "Nisi eu commodo duis magna veniam minim veniam est culpa irure culpa tempor ut. Eu dolore qui cupidatat ut aliqua excepteur quis quis anim amet dolore. Magna commodo ex incididunt sint quis deserunt reprehenderit consequat commodo ipsum. Laborum id culpa dolor deserunt qui adipisicing sint laborum est ullamco eu laborum.",
"registered": "2014-08-13T09:15:27 +04:00",
"latitude": 53.14415,
"longitude": 24.982185,
"tags": [
"cupidatat",
"officia",
"mollit",
"culpa",
"aute",
"officia",
"aliqua"
],
"friends": [
{
"id": 0,
"name": "Flora Atkins"
},
{
"id": 1,
"name": "Melba Nielsen"
},
{
"id": 2,
"name": "Mclaughlin Ray"
}
],
"greeting": "Hello, Stuart Delacruz! You have 5 unread messages.",
"favoriteFruit": "banana"
},
{
"_id": "548f596d13af3f552ed4a454",
"index": 1,
"guid": "97aadd33-2262-46b9-9ecb-b7aac1eb0dd0",
"isActive": true,
"balance": "$1,093.68",
"picture": "http://placehold.it/32x32",
"age": 36,
"eyeColor": "green",
"name": "Carmella Diaz",
"gender": "female",
"company": "DIGIAL",
"email": "carmelladiaz@digial.com",
"phone": "+1 (823) 477-3505",
"address": "330 Rogers Avenue, Wyano, District Of Columbia, 3961",
"about": "Duis excepteur id amet labore culpa cillum sit voluptate velit ad et adipisicing aliquip mollit. Qui sit minim esse labore laborum incididunt occaecat voluptate pariatur. Aliquip non ullamco qui laborum culpa amet Lorem nostrud nostrud. Et Lorem minim aliquip deserunt adipisicing aliquip exercitation commodo laborum proident enim. Laboris non ex consectetur adipisicing eu pariatur incididunt enim. Ullamco nostrud ex reprehenderit fugiat fugiat ut est minim et labore voluptate enim aliqua est.",
"registered": "2014-01-15T22:41:13 +05:00",
"latitude": -69.18865,
"longitude": 112.181127,
"tags": [
"consectetur",
"nulla",
"sunt",
"pariatur",
"dolore",
"consequat",
"quis"
],
"friends": [
{
"id": 0,
"name": "Abigail Jones"
},
{
"id": 1,
"name": "June Harvey"
},
{
"id": 2,
"name": "Ella Francis"
}
],
"greeting": "Hello, Carmella Diaz! You have 10 unread messages.",
"favoriteFruit": "apple"
},
{
"_id": "548f596dd531dff43dfc35f4",
"index": 2,
"guid": "be93dc3b-5169-4280-88f4-7cbba9a39f11",
"isActive": false,
"balance": "$1,856.26",
"picture": "http://placehold.it/32x32",
"age": 34,
"eyeColor": "green",
"name": "Lynch Waller",
"gender": "male",
"company": "ZENOLUX",
"email": "lynchwaller@zenolux.com",
"phone": "+1 (911) 541-2985",
"address": "791 Belvidere Street, Tampico, Oklahoma, 5334",
"about": "Non consectetur cupidatat veniam mollit do ad ea irure. In ut tempor nisi commodo irure ad excepteur nulla aliqua mollit ullamco pariatur exercitation incididunt. Labore eiusmod ut Lorem quis et pariatur deserunt quis et amet aute aliqua. Reprehenderit adipisicing aliquip deserunt deserunt proident do reprehenderit eiusmod aliquip.",
"registered": "2014-05-28T16:10:50 +04:00",
"latitude": -54.663033,
"longitude": 71.722821,
"tags": [
"commodo",
"laboris",
"minim",
"veniam",
"magna",
"duis",
"elit"
],
"friends": [
{
"id": 0,
"name": "Wilma Goodwin"
},
{
"id": 1,
"name": "Evangeline Barry"
},
{
"id": 2,
"name": "Madden Jarvis"
}
],
"greeting": "Hello, Lynch Waller! You have 10 unread messages.",
"favoriteFruit": "apple"
},
{
"_id": "548f596d225c0f2b2fe65631",
"index": 3,
"guid": "c98621a2-cba0-4f3e-8d95-b8d1682275fb",
"isActive": true,
"balance": "$1,674.81",
"picture": "http://placehold.it/32x32",
"age": 20,
"eyeColor": "blue",
"name": "Sharpe Reid",
"gender": "male",
"company": "COMBOGEN",
"email": "sharpereid@combogen.com",
"phone": "+1 (912) 491-3480",
"address": "715 Montauk Court, Hachita, Montana, 382",
"about": "Id aute ut laboris excepteur culpa. Irure nostrud proident amet cillum irure proident tempor reprehenderit ullamco labore nulla. Cupidatat tempor nulla aute culpa sit officia proident magna mollit. Dolor eiusmod reprehenderit minim irure dolore pariatur veniam. Deserunt deserunt velit duis sit mollit occaecat sit. Ipsum labore laboris velit sit occaecat qui id ipsum cupidatat in veniam nostrud elit sint. Lorem exercitation duis exercitation dolor adipisicing anim tempor minim.",
"registered": "2014-05-13T01:44:45 +04:00",
"latitude": 27.526064,
"longitude": 173.307832,
"tags": [
"amet",
"aliqua",
"tempor",
"consectetur",
"sit",
"Lorem",
"velit"
],
"friends": [
{
"id": 0,
"name": "Marquita Leonard"
},
{
"id": 1,
"name": "Merle King"
},
{
"id": 2,
"name": "Velez Valencia"
}
],
"greeting": "Hello, Sharpe Reid! You have 2 unread messages.",
"favoriteFruit": "banana"
},
{
"_id": "548f596d2580858b79569c0d",
"index": 4,
"guid": "8c2958f1-07b6-4231-bfb1-5b7d525d4e1c",
"isActive": true,
"balance": "$3,354.54",
"picture": "http://placehold.it/32x32",
"age": 25,
"eyeColor": "green",
"name": "Melissa Mcclain",
"gender": "female",
"company": "GRUPOLI",
"email": "melissamcclain@grupoli.com",
"phone": "+1 (917) 425-3486",
"address": "800 Lawton Street, Deercroft, Louisiana, 1840",
"about": "Ut est esse occaecat non exercitation officia nisi mollit dolore. Deserunt et amet enim reprehenderit nisi. Laboris fugiat adipisicing do eiusmod qui pariatur. Do magna id eiusmod quis ea do ipsum nulla fugiat qui eu. Eiusmod culpa qui et sint qui id proident dolore cillum ullamco labore sint. Consectetur do sunt exercitation aliquip ullamco irure sunt non velit.",
"registered": "2014-04-07T16:08:57 +04:00",
"latitude": 52.14699,
"longitude": -148.482413,
"tags": [
"sunt",
"aute",
"eu",
"amet",
"excepteur",
"ipsum",
"deserunt"
],
"friends": [
{
"id": 0,
"name": "Kimberley Baird"
},
{
"id": 1,
"name": "Gladys Ferrell"
},
{
"id": 2,
"name": "Keith Whitaker"
}
],
"greeting": "Hello, Melissa Mcclain! You have 9 unread messages.",
"favoriteFruit": "strawberry"
},
{
"_id": "548f596d31cd827248fea957",
"index": 5,
"guid": "64d81b0a-22e0-4a80-85ad-28283d70f145",
"isActive": true,
"balance": "$1,324.96",
"picture": "http://placehold.it/32x32",
"age": 40,
"eyeColor": "green",
"name": "Koch Salazar",
"gender": "male",
"company": "PAPRICUT",
"email": "kochsalazar@papricut.com",
"phone": "+1 (889) 484-3608",
"address": "963 Vanderbilt Avenue, Barrelville, Tennessee, 243",
"about": "Eiusmod nulla fugiat in adipisicing duis cillum in. Commodo culpa qui velit qui ullamco laboris. Duis in occaecat quis et tempor aliquip dolore id laborum tempor excepteur aliqua. Nulla eu anim culpa elit cillum proident ipsum aliquip reprehenderit. Dolore ullamco ex ipsum irure adipisicing consequat adipisicing minim eiusmod. Adipisicing adipisicing proident occaecat nulla deserunt magna eiusmod duis. Adipisicing nisi esse enim cupidatat cupidatat.",
"registered": "2014-02-25T00:37:05 +05:00",
"latitude": 51.4303,
"longitude": -81.290028,
"tags": [
"magna",
"fugiat",
"Lorem",
"sit",
"non",
"incididunt",
"amet"
],
"friends": [
{
"id": 0,
"name": "Adeline Obrien"
},
{
"id": 1,
"name": "Minnie Vargas"
},
{
"id": 2,
"name": "Marcia Sharp"
}
],
"greeting": "Hello, Koch Salazar! You have 9 unread messages.",
"favoriteFruit": "banana"
},
{
"_id": "548f596d977c4a6318bbbd48",
"index": 6,
"guid": "ae0da695-1c88-4ae9-a359-81c7a43bf509",
"isActive": false,
"balance": "$2,228.76",
"picture": "http://placehold.it/32x32",
"age": 23,
"eyeColor": "blue",
"name": "Carr Kim",
"gender": "male",
"company": "EARTHPLEX",
"email": "carrkim@earthplex.com",
"phone": "+1 (887) 557-2801",
"address": "244 Denton Place, Whitewater, North Dakota, 4946",
"about": "Laboris aliqua consectetur ex nisi et id sit ea aliquip et reprehenderit. Cupidatat deserunt eu irure aliqua consequat do eiusmod non non quis tempor aliquip est nisi. Sit magna officia voluptate culpa ipsum. Excepteur labore labore reprehenderit esse enim.",
"registered": "2014-10-31T10:24:54 +04:00",
"latitude": 33.128339,
"longitude": -115.816549,
"tags": [
"fugiat",
"magna",
"ullamco",
"sunt",
"excepteur",
"id",
"laborum"
],
"friends": [
{
"id": 0,
"name": "Solis Hinton"
},
{
"id": 1,
"name": "Eloise Harrison"
},
{
"id": 2,
"name": "Enid Tillman"
}
],
"greeting": "Hello, Carr Kim! You have 5 unread messages.",
"favoriteFruit": "apple"
}
]
EOS
### JSON 1.8.1
$ jruby ~/tmp/json_contention.rb
337.920000 0.570000 338.490000 ( 57.955000)
### JSON 1.8.1 w/ RuntimeInfo patch applied
$ jruby ~/tmp/json_contention.rb
326.400000 0.580000 326.980000 ( 43.084000)
diff --git a/java/src/json/ext/Parser.java b/java/src/json/ext/Parser.java
index 6cb5886..452986d 100644
--- a/java/src/json/ext/Parser.java
+++ b/java/src/json/ext/Parser.java
@@ -130,7 +130,7 @@ public class Parser extends RubyObject {
*
* <dt><code>:create_additions</code>
* <dd>If set to <code>false</code>, the Parser doesn't create additions
- * even if a matchin class and <code>create_id</code> was found. This option
+ * even if a matching class and <code>create_id</code> was found. This option
* defaults to <code>true</code>.
*
* <dt><code>:object_class</code>
@@ -304,6 +304,7 @@ public class Parser extends RubyObject {
private static class ParserSession {
private final Parser parser;
private final ThreadContext context;
+ private final RuntimeInfo info;
private final ByteList byteList;
private final ByteList view;
private final byte[] data;
@@ -318,6 +319,7 @@ public class Parser extends RubyObject {
private ParserSession(Parser parser, ThreadContext context) {
this.parser = parser;
this.context = context;
+ this.info = RuntimeInfo.forRuntime(context.getRuntime());
this.byteList = parser.checkAndGetSource().getByteList();
this.data = byteList.unsafeBytes();
this.view = new ByteList(data, false);
@@ -337,11 +339,11 @@ public class Parser extends RubyObject {
}
-// line 363 "Parser.rl"
+// line 365 "Parser.rl"
-// line 345 "Parser.java"
+// line 347 "Parser.java"
private static byte[] init__JSON_value_actions_0()
{
return new byte [] {
@@ -455,7 +457,7 @@ static final int JSON_value_error = 0;
static final int JSON_value_en_main = 1;
-// line 469 "Parser.rl"
+// line 471 "Parser.rl"
void parseValue(ParserResult res, int p, int pe) {
@@ -463,14 +465,14 @@ static final int JSON_value_en_main = 1;
IRubyObject result = null;
-// line 467 "Parser.java"
+// line 469 "Parser.java"
{
cs = JSON_value_start;
}
-// line 476 "Parser.rl"
+// line 478 "Parser.rl"
-// line 474 "Parser.java"
+// line 476 "Parser.java"
{
int _klen;
int _trans = 0;
@@ -496,13 +498,13 @@ case 1:
while ( _nacts-- > 0 ) {
switch ( _JSON_value_actions[_acts++] ) {
case 9:
-// line 454 "Parser.rl"
+// line 456 "Parser.rl"
{
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
}
break;
-// line 506 "Parser.java"
+// line 508 "Parser.java"
}
}
@@ -565,25 +567,25 @@ case 1:
switch ( _JSON_value_actions[_acts++] )
{
case 0:
-// line 371 "Parser.rl"
+// line 373 "Parser.rl"
{
result = getRuntime().getNil();
}
break;
case 1:
-// line 374 "Parser.rl"
+// line 376 "Parser.rl"
{
result = getRuntime().getFalse();
}
break;
case 2:
-// line 377 "Parser.rl"
+// line 379 "Parser.rl"
{
result = getRuntime().getTrue();
}
break;
case 3:
-// line 380 "Parser.rl"
+// line 382 "Parser.rl"
{
if (parser.allowNaN) {
result = getConstant(CONST_NAN);
@@ -593,7 +595,7 @@ case 1:
}
break;
case 4:
-// line 387 "Parser.rl"
+// line 389 "Parser.rl"
{
if (parser.allowNaN) {
result = getConstant(CONST_INFINITY);
@@ -603,7 +605,7 @@ case 1:
}
break;
case 5:
-// line 394 "Parser.rl"
+// line 396 "Parser.rl"
{
if (pe > p + 9 - (parser.quirksMode ? 1 : 0) &&
absSubSequence(p, p + 9).equals(JSON_MINUS_INFINITY)) {
@@ -632,7 +634,7 @@ case 1:
}
break;
case 6:
-// line 420 "Parser.rl"
+// line 422 "Parser.rl"
{
parseString(res, p, pe);
if (res.result == null) {
@@ -645,7 +647,7 @@ case 1:
}
break;
case 7:
-// line 430 "Parser.rl"
+// line 432 "Parser.rl"
{
currentNesting++;
parseArray(res, p, pe);
@@ -660,7 +662,7 @@ case 1:
}
break;
case 8:
-// line 442 "Parser.rl"
+// line 444 "Parser.rl"
{
currentNesting++;
parseObject(res, p, pe);
@@ -674,7 +676,7 @@ case 1:
}
}
break;
-// line 678 "Parser.java"
+// line 680 "Parser.java"
}
}
}
@@ -694,7 +696,7 @@ case 5:
break; }
}
-// line 477 "Parser.rl"
+// line 479 "Parser.rl"
if (cs >= JSON_value_first_final && result != null) {
res.update(result, p);
@@ -704,7 +706,7 @@ case 5:
}
-// line 708 "Parser.java"
+// line 710 "Parser.java"
private static byte[] init__JSON_integer_actions_0()
{
return new byte [] {
@@ -803,7 +805,7 @@ static final int JSON_integer_error = 0;
static final int JSON_integer_en_main = 1;
-// line 496 "Parser.rl"
+// line 498 "Parser.rl"
void parseInteger(ParserResult res, int p, int pe) {
@@ -821,15 +823,15 @@ static final int JSON_integer_en_main = 1;
int cs = EVIL;
-// line 825 "Parser.java"
+// line 827 "Parser.java"
{
cs = JSON_integer_start;
}
-// line 513 "Parser.rl"
+// line 515 "Parser.rl"
int memo = p;
-// line 833 "Parser.java"
+// line 835 "Parser.java"
{
int _klen;
int _trans = 0;
@@ -910,13 +912,13 @@ case 1:
switch ( _JSON_integer_actions[_acts++] )
{
case 0:
-// line 490 "Parser.rl"
+// line 492 "Parser.rl"
{
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
}
break;
-// line 920 "Parser.java"
+// line 922 "Parser.java"
}
}
}
@@ -936,7 +938,7 @@ case 5:
break; }
}
-// line 515 "Parser.rl"
+// line 517 "Parser.rl"
if (cs < JSON_integer_first_final) {
return -1;
@@ -958,7 +960,7 @@ case 5:
}
-// line 962 "Parser.java"
+// line 964 "Parser.java"
private static byte[] init__JSON_float_actions_0()
{
return new byte [] {
@@ -1060,7 +1062,7 @@ static final int JSON_float_error = 0;
static final int JSON_float_en_main = 1;
-// line 550 "Parser.rl"
+// line 552 "Parser.rl"
void parseFloat(ParserResult res, int p, int pe) {
@@ -1078,15 +1080,15 @@ static final int JSON_float_en_main = 1;
int cs = EVIL;
-// line 1082 "Parser.java"
+// line 1084 "Parser.java"
{
cs = JSON_float_start;
}
-// line 567 "Parser.rl"
+// line 569 "Parser.rl"
int memo = p;
-// line 1090 "Parser.java"
+// line 1092 "Parser.java"
{
int _klen;
int _trans = 0;
@@ -1167,13 +1169,13 @@ case 1:
switch ( _JSON_float_actions[_acts++] )
{
case 0:
-// line 541 "Parser.rl"
+// line 543 "Parser.rl"
{
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
}
break;
-// line 1177 "Parser.java"
+// line 1179 "Parser.java"
}
}
}
@@ -1193,7 +1195,7 @@ case 5:
break; }
}
-// line 569 "Parser.rl"
+// line 571 "Parser.rl"
if (cs < JSON_float_first_final) {
return -1;
@@ -1209,7 +1211,7 @@ case 5:
}
-// line 1213 "Parser.java"
+// line 1215 "Parser.java"
private static byte[] init__JSON_string_actions_0()
{
return new byte [] {
@@ -1311,7 +1313,7 @@ static final int JSON_string_error = 0;
static final int JSON_string_en_main = 1;
-// line 614 "Parser.rl"
+// line 616 "Parser.rl"
void parseString(ParserResult res, int p, int pe) {
@@ -1319,15 +1321,15 @@ static final int JSON_string_en_main = 1;
IRubyObject result = null;
-// line 1323 "Parser.java"
+// line 1325 "Parser.java"
{
cs = JSON_string_start;
}
-// line 621 "Parser.rl"
+// line 623 "Parser.rl"
int memo = p;
-// line 1331 "Parser.java"
+// line 1333 "Parser.java"
{
int _klen;
int _trans = 0;
@@ -1408,7 +1410,7 @@ case 1:
switch ( _JSON_string_actions[_acts++] )
{
case 0:
-// line 589 "Parser.rl"
+// line 591 "Parser.rl"
{
int offset = byteList.begin();
ByteList decoded = decoder.decode(byteList, memo + 1 - offset,
@@ -1423,13 +1425,13 @@ case 1:
}
break;
case 1:
-// line 602 "Parser.rl"
+// line 604 "Parser.rl"
{
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
}
break;
-// line 1433 "Parser.java"
+// line 1435 "Parser.java"
}
}
}
@@ -1449,7 +1451,7 @@ case 5:
break; }
}
-// line 623 "Parser.rl"
+// line 625 "Parser.rl"
if (parser.createAdditions) {
RubyHash match_string = parser.match_string;
@@ -1476,8 +1478,7 @@ case 5:
}
}
- if (cs >= JSON_string_first_final && result != null) {
- RuntimeInfo info = RuntimeInfo.forRuntime(context.getRuntime());
+ if (cs >= JSON_string_first_final && result != null) {
if (info.encodingsSupported() && result instanceof RubyString) {
((RubyString)result).force_encoding(context, info.utf8.get());
}
@@ -1488,7 +1489,7 @@ case 5:
}
-// line 1492 "Parser.java"
+// line 1493 "Parser.java"
private static byte[] init__JSON_array_actions_0()
{
return new byte [] {
@@ -1601,7 +1602,7 @@ static final int JSON_array_error = 0;
static final int JSON_array_en_main = 1;
-// line 697 "Parser.rl"
+// line 698 "Parser.rl"
void parseArray(ParserResult res, int p, int pe) {
@@ -1621,14 +1622,14 @@ static final int JSON_array_en_main = 1;
}
-// line 1625 "Parser.java"
+// line 1626 "Parser.java"
{
cs = JSON_array_start;
}
-// line 716 "Parser.rl"
+// line 717 "Parser.rl"
-// line 1632 "Parser.java"
+// line 1633 "Parser.java"
{
int _klen;
int _trans = 0;
@@ -1709,7 +1710,7 @@ case 1:
switch ( _JSON_array_actions[_acts++] )
{
case 0:
-// line 666 "Parser.rl"
+// line 667 "Parser.rl"
{
parseValue(res, p, pe);
if (res.result == null) {
@@ -1726,13 +1727,13 @@ case 1:
}
break;
case 1:
-// line 681 "Parser.rl"
+// line 682 "Parser.rl"
{
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
}
break;
-// line 1736 "Parser.java"
+// line 1737 "Parser.java"
}
}
}
@@ -1752,7 +1753,7 @@ case 5:
break; }
}
-// line 717 "Parser.rl"
+// line 718 "Parser.rl"
if (cs >= JSON_array_first_final) {
res.update(result, p + 1);
@@ -1762,7 +1763,7 @@ case 5:
}
-// line 1766 "Parser.java"
+// line 1767 "Parser.java"
private static byte[] init__JSON_object_actions_0()
{
return new byte [] {
@@ -1885,7 +1886,7 @@ static final int JSON_object_error = 0;
static final int JSON_object_en_main = 1;
-// line 776 "Parser.rl"
+// line 777 "Parser.rl"
void parseObject(ParserResult res, int p, int pe) {
@@ -1910,14 +1911,14 @@ static final int JSON_object_en_main = 1;
}
-// line 1914 "Parser.java"
+// line 1915 "Parser.java"
{
cs = JSON_object_start;
}
-// line 800 "Parser.rl"
+// line 801 "Parser.rl"
-// line 1921 "Parser.java"
+// line 1922 "Parser.java"
{
int _klen;
int _trans = 0;
@@ -1998,7 +1999,7 @@ case 1:
switch ( _JSON_object_actions[_acts++] )
{
case 0:
-// line 731 "Parser.rl"
+// line 732 "Parser.rl"
{
parseValue(res, p, pe);
if (res.result == null) {
@@ -2015,7 +2016,7 @@ case 1:
}
break;
case 1:
-// line 746 "Parser.rl"
+// line 747 "Parser.rl"
{
parseString(res, p, pe);
if (res.result == null) {
@@ -2035,13 +2036,13 @@ case 1:
}
break;
case 2:
-// line 764 "Parser.rl"
+// line 765 "Parser.rl"
{
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
}
break;
-// line 2045 "Parser.java"
+// line 2046 "Parser.java"
}
}
}
@@ -2061,7 +2062,7 @@ case 5:
break; }
}
-// line 801 "Parser.rl"
+// line 802 "Parser.rl"
if (cs < JSON_object_first_final) {
res.update(null, p + 1);
@@ -2094,7 +2095,7 @@ case 5:
}
-// line 2098 "Parser.java"
+// line 2099 "Parser.java"
private static byte[] init__JSON_actions_0()
{
return new byte [] {
@@ -2198,7 +2199,7 @@ static final int JSON_error = 0;
static final int JSON_en_main = 1;
-// line 866 "Parser.rl"
+// line 867 "Parser.rl"
public IRubyObject parseStrict() {
@@ -2208,16 +2209,16 @@ static final int JSON_en_main = 1;
ParserResult res = new ParserResult();
-// line 2212 "Parser.java"
+// line 2213 "Parser.java"
{
cs = JSON_start;
}
-// line 875 "Parser.rl"
+// line 876 "Parser.rl"
p = byteList.begin();
pe = p + byteList.length();
-// line 2221 "Parser.java"
+// line 2222 "Parser.java"
{
int _klen;
int _trans = 0;
@@ -2298,7 +2299,7 @@ case 1:
switch ( _JSON_actions[_acts++] )
{
case 0:
-// line 838 "Parser.rl"
+// line 839 "Parser.rl"
{
currentNesting = 1;
parseObject(res, p, pe);
@@ -2312,7 +2313,7 @@ case 1:
}
break;
case 1:
-// line 850 "Parser.rl"
+// line 851 "Parser.rl"
{
currentNesting = 1;
parseArray(res, p, pe);
@@ -2325,7 +2326,7 @@ case 1:
}
}
break;
-// line 2329 "Parser.java"
+// line 2330 "Parser.java"
}
}
}
@@ -2345,7 +2346,7 @@ case 5:
break; }
}
-// line 878 "Parser.rl"
+// line 879 "Parser.rl"
if (cs >= JSON_first_final && p == pe) {
return result;
@@ -2355,7 +2356,7 @@ case 5:
}
-// line 2359 "Parser.java"
+// line 2360 "Parser.java"
private static byte[] init__JSON_quirks_mode_actions_0()
{
return new byte [] {
@@ -2458,7 +2459,7 @@ static final int JSON_quirks_mode_error = 0;
static final int JSON_quirks_mode_en_main = 1;
-// line 906 "Parser.rl"
+// line 907 "Parser.rl"
public IRubyObject parseQuirksMode() {
@@ -2468,16 +2469,16 @@ static final int JSON_quirks_mode_en_main = 1;
ParserResult res = new ParserResult();
-// line 2472 "Parser.java"
+// line 2473 "Parser.java"
{
cs = JSON_quirks_mode_start;
}
-// line 915 "Parser.rl"
+// line 916 "Parser.rl"
p = byteList.begin();
pe = p + byteList.length();
-// line 2481 "Parser.java"
+// line 2482 "Parser.java"
{
int _klen;
int _trans = 0;
@@ -2558,7 +2559,7 @@ case 1:
switch ( _JSON_quirks_mode_actions[_acts++] )
{
case 0:
-// line 892 "Parser.rl"
+// line 893 "Parser.rl"
{
parseValue(res, p, pe);
if (res.result == null) {
@@ -2570,7 +2571,7 @@ case 1:
}
}
break;
-// line 2574 "Parser.java"
+// line 2575 "Parser.java"
}
}
}
@@ -2590,7 +2591,7 @@ case 5:
break; }
}
-// line 918 "Parser.rl"
+// line 919 "Parser.rl"
if (cs >= JSON_quirks_mode_first_final && p == pe) {
return result;
diff --git a/java/src/json/ext/Parser.rl b/java/src/json/ext/Parser.rl
index 7dcdd2e..d6e8daa 100644
--- a/java/src/json/ext/Parser.rl
+++ b/java/src/json/ext/Parser.rl
@@ -302,6 +302,7 @@ public class Parser extends RubyObject {
private static class ParserSession {
private final Parser parser;
private final ThreadContext context;
+ private final RuntimeInfo info;
private final ByteList byteList;
private final ByteList view;
private final byte[] data;
@@ -316,6 +317,7 @@ public class Parser extends RubyObject {
private ParserSession(Parser parser, ThreadContext context) {
this.parser = parser;
this.context = context;
+ this.info = RuntimeInfo.forRuntime(context.getRuntime());
this.byteList = parser.checkAndGetSource().getByteList();
this.data = byteList.unsafeBytes();
this.view = new ByteList(data, false);
@@ -646,8 +648,7 @@ public class Parser extends RubyObject {
}
}
- if (cs >= JSON_string_first_final && result != null) {
- RuntimeInfo info = RuntimeInfo.forRuntime(context.getRuntime());
+ if (cs >= JSON_string_first_final && result != null) {
if (info.encodingsSupported() && result instanceof RubyString) {
((RubyString)result).force_encoding(context, info.utf8.get());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment