From: sam.saffron@... Date: 2019-10-08T23:34:52+00:00 Subject: [ruby-core:95285] [Ruby master Feature#16029] Expose fstring related APIs to C-extensions Issue #16029 has been updated by sam.saffron (Sam Saffron). I think when it gets called it expects to reuse the memory allocated by the cstr eventually https://github.com//blob/96753e8475ee69537134ab3d966c3d25cb5c467c/string.c#L287-L292 So if your library is in charge of the memory for the object this is not desirable, you want to simply ask the question "do you have an fstring for the current string eg" VALUE rb_fstring_lookup(char *ptr); This non const char means it would not take ownership and the thing can return Qnil if there is no fstring. Then if 99.999% of the string your library has are already fstrings, the lookup becomes a super cheap function you can use to lookup. ---------------------------------------- Feature #16029: Expose fstring related APIs to C-extensions https://bugs.ruby-lang.org/issues/16029#change-81965 * Author: byroot (Jean Boussier) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- As discussed with @tenderlove here: https://github.com/ruby/ruby/pull/2287#issuecomment-513865160 We'd like to update various data format parsers (JSON, MessagePack, etc) to add the possibility to deduplicate strings while parsing. But unfortunately the `rb_fstring_*` family of functions isn't available to C-extensions, so the only available fallback is `rb_funcall(str, rb_intern("-@"))` which most parsers will likely consider too slow. So the various `rb_fstring_*` functions would need to be public. Proposed patch: https://github.com/ruby/ruby/pull/2299 -- https://bugs.ruby-lang.org/ Unsubscribe: