Skip to content

Commit 35cf2b8

Browse files
committed
Remove String#-@ check in extconf.rb
Now that older rubies have been droped, we no longer need to check for all that.
1 parent 7e0f665 commit 35cf2b8

File tree

3 files changed

+21
-68
lines changed

3 files changed

+21
-68
lines changed

ext/json/ext/parser/extconf.rb

-25
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,6 @@
44
have_func("rb_enc_raise", "ruby.h")
55
have_func("rb_enc_interned_str", "ruby.h")
66

7-
# checking if String#-@ (str_uminus) dedupes... '
8-
begin
9-
a = -(%w(t e s t).join)
10-
b = -(%w(t e s t).join)
11-
if a.equal?(b)
12-
$CFLAGS << ' -DSTR_UMINUS_DEDUPE=1 '
13-
else
14-
$CFLAGS << ' -DSTR_UMINUS_DEDUPE=0 '
15-
end
16-
rescue NoMethodError
17-
$CFLAGS << ' -DSTR_UMINUS_DEDUPE=0 '
18-
end
19-
20-
# checking if String#-@ (str_uminus) directly interns frozen strings... '
21-
begin
22-
s = rand.to_s.freeze
23-
if (-s).equal?(s) && (-s.dup).equal?(s)
24-
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=1 '
25-
else
26-
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=0 '
27-
end
28-
rescue NoMethodError
29-
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=0 '
30-
end
31-
327
append_cflags("-std=c99")
338

349
create_makefile 'json/ext/parser'

ext/json/ext/parser/parser.c

+19-30
Original file line numberDiff line numberDiff line change
@@ -1465,19 +1465,8 @@ static inline VALUE build_string(const char *start, const char *end, bool intern
14651465
# else
14661466
result = rb_utf8_str_new(start, (long)(end - start));
14671467
if (intern) {
1468-
# if STR_UMINUS_DEDUPE_FROZEN
1469-
// Starting from MRI 3.0 it is preferable to freeze the string
1470-
// before deduplication so that it can be interned directly
1471-
// otherwise it would be duplicated first which is wasteful.
1472-
result = rb_funcall(rb_str_freeze(result), i_uminus, 0);
1473-
# elif STR_UMINUS_DEDUPE
1474-
// MRI 2.5 and older do not deduplicate strings that are already
1475-
// frozen.
1476-
result = rb_funcall(result, i_uminus, 0);
1477-
# else
1478-
result = rb_str_freeze(result);
1479-
# endif
1480-
}
1468+
result = rb_funcall(rb_str_freeze(result), i_uminus, 0);
1469+
}
14811470
# endif
14821471

14831472
if (symbolize) {
@@ -1613,15 +1602,15 @@ static VALUE json_string_unescape(char *string, char *stringEnd, bool intern, bo
16131602
}
16141603

16151604

1616-
#line 1617 "parser.c"
1605+
#line 1606 "parser.c"
16171606
enum {JSON_string_start = 1};
16181607
enum {JSON_string_first_final = 8};
16191608
enum {JSON_string_error = 0};
16201609

16211610
enum {JSON_string_en_main = 1};
16221611

16231612

1624-
#line 645 "parser.rl"
1613+
#line 634 "parser.rl"
16251614

16261615

16271616
static int
@@ -1642,15 +1631,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
16421631
VALUE match_string;
16431632

16441633

1645-
#line 1646 "parser.c"
1634+
#line 1635 "parser.c"
16461635
{
16471636
cs = JSON_string_start;
16481637
}
16491638

1650-
#line 665 "parser.rl"
1639+
#line 654 "parser.rl"
16511640
json->memo = p;
16521641

1653-
#line 1654 "parser.c"
1642+
#line 1643 "parser.c"
16541643
{
16551644
if ( p == pe )
16561645
goto _test_eof;
@@ -1675,7 +1664,7 @@ case 2:
16751664
goto st0;
16761665
goto st2;
16771666
tr2:
1678-
#line 632 "parser.rl"
1667+
#line 621 "parser.rl"
16791668
{
16801669
*result = json_string_unescape(json->memo + 1, p, json->parsing_name || json-> freeze, json->parsing_name && json->symbolize_names);
16811670
if (NIL_P(*result)) {
@@ -1685,14 +1674,14 @@ case 2:
16851674
{p = (( p + 1))-1;}
16861675
}
16871676
}
1688-
#line 642 "parser.rl"
1677+
#line 631 "parser.rl"
16891678
{ p--; {p++; cs = 8; goto _out;} }
16901679
goto st8;
16911680
st8:
16921681
if ( ++p == pe )
16931682
goto _test_eof8;
16941683
case 8:
1695-
#line 1696 "parser.c"
1684+
#line 1685 "parser.c"
16961685
goto st0;
16971686
st3:
16981687
if ( ++p == pe )
@@ -1768,7 +1757,7 @@ case 7:
17681757
_out: {}
17691758
}
17701759

1771-
#line 667 "parser.rl"
1760+
#line 656 "parser.rl"
17721761

17731762
if (json->create_additions && RTEST(match_string = json->match_string)) {
17741763
VALUE klass;
@@ -1965,15 +1954,15 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
19651954
}
19661955

19671956

1968-
#line 1969 "parser.c"
1957+
#line 1958 "parser.c"
19691958
enum {JSON_start = 1};
19701959
enum {JSON_first_final = 10};
19711960
enum {JSON_error = 0};
19721961

19731962
enum {JSON_en_main = 1};
19741963

19751964

1976-
#line 877 "parser.rl"
1965+
#line 866 "parser.rl"
19771966

19781967

19791968
/*
@@ -1991,16 +1980,16 @@ static VALUE cParser_parse(VALUE self)
19911980
GET_PARSER;
19921981

19931982

1994-
#line 1995 "parser.c"
1983+
#line 1984 "parser.c"
19951984
{
19961985
cs = JSON_start;
19971986
}
19981987

1999-
#line 894 "parser.rl"
1988+
#line 883 "parser.rl"
20001989
p = json->source;
20011990
pe = p + json->len;
20021991

2003-
#line 2004 "parser.c"
1992+
#line 1993 "parser.c"
20041993
{
20051994
if ( p == pe )
20061995
goto _test_eof;
@@ -2034,7 +2023,7 @@ case 1:
20342023
cs = 0;
20352024
goto _out;
20362025
tr2:
2037-
#line 869 "parser.rl"
2026+
#line 858 "parser.rl"
20382027
{
20392028
char *np = JSON_parse_value(json, p, pe, &result, 0);
20402029
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
@@ -2044,7 +2033,7 @@ cs = 0;
20442033
if ( ++p == pe )
20452034
goto _test_eof10;
20462035
case 10:
2047-
#line 2048 "parser.c"
2036+
#line 2037 "parser.c"
20482037
switch( (*p) ) {
20492038
case 13: goto st10;
20502039
case 32: goto st10;
@@ -2133,7 +2122,7 @@ case 9:
21332122
_out: {}
21342123
}
21352124

2136-
#line 897 "parser.rl"
2125+
#line 886 "parser.rl"
21372126

21382127
if (cs >= JSON_first_final && p == pe) {
21392128
return result;

ext/json/ext/parser/parser.rl

+2-13
Original file line numberDiff line numberDiff line change
@@ -476,19 +476,8 @@ static inline VALUE build_string(const char *start, const char *end, bool intern
476476
# else
477477
result = rb_utf8_str_new(start, (long)(end - start));
478478
if (intern) {
479-
# if STR_UMINUS_DEDUPE_FROZEN
480-
// Starting from MRI 3.0 it is preferable to freeze the string
481-
// before deduplication so that it can be interned directly
482-
// otherwise it would be duplicated first which is wasteful.
483-
result = rb_funcall(rb_str_freeze(result), i_uminus, 0);
484-
# elif STR_UMINUS_DEDUPE
485-
// MRI 2.5 and older do not deduplicate strings that are already
486-
// frozen.
487-
result = rb_funcall(result, i_uminus, 0);
488-
# else
489-
result = rb_str_freeze(result);
490-
# endif
491-
}
479+
result = rb_funcall(rb_str_freeze(result), i_uminus, 0);
480+
}
492481
# endif
493482

494483
if (symbolize) {

0 commit comments

Comments
 (0)