[ruby-core:95316] [Ruby master Feature#16029] Expose fstring related APIs to C-extensions
From:
sam.saffron@...
Date:
2019-10-14 05:22:15 UTC
List:
ruby-core #95316
Issue #16029 has been updated by sam.saffron (Sam Saffron).
I was thinking something like?
```
VALUE
rb_fstring_lookup(char *ptr, rb_encoding *enc)
{
st_data_t fstring;
struct RString fake_str;
setup_fake_str(&fake_str, ptr, len, ENCINDEX_US_ASCII)
st_table *frozen_strings = rb_vm_fstring_table();
if (!st_lookup(frozen_strings, (st_data_t)fake_str, &fstring)) {
return Qnil;
}
return ret;
}
```
----------------------------------------
Feature #16029: Expose fstring related APIs to C-extensions
https://bugs.ruby-lang.org/issues/16029#change-82018
* 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>