Skip to content

Commit

Permalink
Implement a freeze: parser option
Browse files Browse the repository at this point in the history
If set to true all parsed objects will be
immediately frozen, and strings will be
deduplicated if the Ruby implementation
allows it.
  • Loading branch information
byroot committed Sep 15, 2020
1 parent c5083b2 commit 3a56c08
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 120 deletions.
26 changes: 26 additions & 0 deletions ext/json/ext/parser/extconf.rb
Expand Up @@ -3,4 +3,30 @@

have_func("rb_enc_raise", "ruby.h")

# checking if String#-@ (str_uminus) dedupes... '
begin
a = -(%w(t e s t).join)
b = -(%w(t e s t).join)
if a.equal?(b)
$CFLAGS << ' -DSTR_UMINUS_DEDUPE=1 '
else
$CFLAGS << ' -DSTR_UMINUS_DEDUPE=0 '
end
rescue NoMethodError
$CFLAGS << ' -DSTR_UMINUS_DEDUPE=0 '
end

# checking if String#-@ (str_uminus) directly interns frozen strings... '
begin
require 'objspace'
s = rand.to_s.freeze
if (-s).equal?(s) && ObjectSpace.dump(s).include?('"fstring":true')
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=1 '
else
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=0 '
end
rescue NoMethodError
$CFLAGS << ' -DSTR_UMINUS_DEDUPE_FROZEN=0 '
end

create_makefile 'json/ext/parser'

0 comments on commit 3a56c08

Please sign in to comment.