ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: sam.saffron@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:95285] [Ruby master Feature#16029] Expose fstring related APIs to C-extensions
Date: Tue, 08 Oct 2019 23:34:52 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-81965.20191008233452.7ac610c6cb33a0a6@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-16029.20190731010619@ruby-lang.org

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/

  parent reply	other threads:[~2019-10-08 23:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-16029.20190731010619@ruby-lang.org>
2019-07-31  1:06 ` [ruby-core:94064] [Ruby master Feature#16029] Expose fstring related APIs to C-extensions jean.boussier
2019-09-03 15:32 ` [ruby-core:94761] " jean.boussier
2019-09-03 16:42 ` [ruby-core:94763] " mame
2019-10-07 22:25 ` [ruby-core:95269] " sam.saffron
2019-10-08 11:07 ` [ruby-core:95276] " jean.boussier
2019-10-08 23:34 ` sam.saffron [this message]
2019-10-14  5:22 ` [ruby-core:95316] " sam.saffron
2019-10-17  5:55 ` [ruby-core:95381] " ko1
2019-10-17 21:09 ` [ruby-core:95403] " sam.saffron
2019-10-28 12:59 ` [ruby-core:95575] " jean.boussier
2019-12-31  6:46 ` [ruby-core:96607] " sam.saffron
2020-01-01 11:05 ` [ruby-core:96613] " jean.boussier
2020-01-05  0:58 ` [ruby-core:96666] " sam.saffron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-81965.20191008233452.7ac610c6cb33a0a6@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).