[前][次][番号順一覧][スレッド一覧]

ruby-changes:58240

From: Florian <ko1@a...>
Date: Mon, 14 Oct 2019 19:59:40 +0900 (JST)
Subject: [ruby-changes:58240] 7376d70cb0 (master): [flori/json] Only attempt to resize strings not other objects

https://git.ruby-lang.org/ruby.git/commit/?id=7376d70cb0

From 7376d70cb0817158a9ce0ef433872be5ca7af56b Mon Sep 17 00:00:00 2001
From: Florian Frank <flori@p...>
Date: Mon, 29 Apr 2019 15:56:14 +0200
Subject: [flori/json] Only attempt to resize strings not other objects

https://github.com/flori/json/commit/167ada8da7

diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c
index 11cd290..0f98cf9 100644
--- a/ext/json/parser/parser.c
+++ b/ext/json/parser/parser.c
@@ -1676,10 +1676,8 @@ case 7: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1676
 
     if (json->symbolize_names && json->parsing_name) {
       *result = rb_str_intern(*result);
-    } else {
-          if (RB_TYPE_P(*result, T_STRING)) {
-              rb_str_resize(*result, RSTRING_LEN(*result));
-          }
+    } else if (RB_TYPE_P(*result, T_STRING)) {
+      rb_str_resize(*result, RSTRING_LEN(*result));
     }
     if (cs >= JSON_string_first_final) {
         return p + 1;
@@ -1850,7 +1848,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1848
 }
 
 
-#line 1854 "parser.c"
+#line 1852 "parser.c"
 enum {JSON_start = 1};
 enum {JSON_first_final = 10};
 enum {JSON_error = 0};
@@ -1858,7 +1856,7 @@ enum {JSON_error = 0}; https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1856
 enum {JSON_en_main = 1};
 
 
-#line 762 "parser.rl"
+#line 760 "parser.rl"
 
 
 /*
@@ -1875,16 +1873,16 @@ static VALUE cParser_parse(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1873
   GET_PARSER;
 
 
-#line 1879 "parser.c"
+#line 1877 "parser.c"
 	{
 	cs = JSON_start;
 	}
 
-#line 778 "parser.rl"
+#line 776 "parser.rl"
   p = json->source;
   pe = p + json->len;
 
-#line 1888 "parser.c"
+#line 1886 "parser.c"
 	{
 	if ( p == pe )
 		goto _test_eof;
@@ -1918,7 +1916,7 @@ st0: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1916
 cs = 0;
 	goto _out;
 tr2:
-#line 754 "parser.rl"
+#line 752 "parser.rl"
 	{
         char *np = JSON_parse_value(json, p, pe, &result, 0);
         if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
@@ -1928,7 +1926,7 @@ st10: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1926
 	if ( ++p == pe )
 		goto _test_eof10;
 case 10:
-#line 1932 "parser.c"
+#line 1930 "parser.c"
 	switch( (*p) ) {
 		case 13: goto st10;
 		case 32: goto st10;
@@ -2017,7 +2015,7 @@ case 9: https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L2015
 	_out: {}
 	}
 
-#line 781 "parser.rl"
+#line 779 "parser.rl"
 
   if (cs >= JSON_first_final && p == pe) {
     return result;
diff --git a/ext/json/parser/parser.rl b/ext/json/parser/parser.rl
index e634f44..6b38bb2 100644
--- a/ext/json/parser/parser.rl
+++ b/ext/json/parser/parser.rl
@@ -571,10 +571,8 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.rl#L571
 
     if (json->symbolize_names && json->parsing_name) {
       *result = rb_str_intern(*result);
-    } else {
-          if (RB_TYPE_P(*result, T_STRING)) {
-              rb_str_resize(*result, RSTRING_LEN(*result));
-          }
+    } else if (RB_TYPE_P(*result, T_STRING)) {
+      rb_str_resize(*result, RSTRING_LEN(*result));
     }
     if (cs >= JSON_string_first_final) {
         return p + 1;
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]