kcar RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* [PATCH] use rb_fstring from Ruby 2.1.0dev if available
@ 2013-10-12  3:18 Eric Wong
  2013-10-12  6:59 ` Eric Wong
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Wong @ 2013-10-12  3:18 UTC (permalink / raw)
  To: kcar

This should be safe after r43210 from ruby trunk
---
 ext/kcar/extconf.rb |  1 +
 ext/kcar/kcar.rl    | 12 +++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/ext/kcar/extconf.rb b/ext/kcar/extconf.rb
index 4f19c4a..1ac6847 100644
--- a/ext/kcar/extconf.rb
+++ b/ext/kcar/extconf.rb
@@ -7,6 +7,7 @@ have_macro("SIZEOF_OFF_T", "ruby.h") or check_sizeof("off_t", "sys/types.h")
 have_macro("SIZEOF_LONG", "ruby.h") or check_sizeof("long", "sys/types.h")
 have_func("rb_str_set_len", "ruby.h")
 have_func("rb_str_modify", "ruby.h")
+have_func("rb_fstring", "ruby.h")
 
 # -fPIC is needed for Rubinius, MRI already uses it regardless
 with_cflags($CFLAGS + " -fPIC ") do
diff --git a/ext/kcar/kcar.rl b/ext/kcar/kcar.rl
index e812279..7d3f9ae 100644
--- a/ext/kcar/kcar.rl
+++ b/ext/kcar/kcar.rl
@@ -192,6 +192,16 @@ static void write_cont_value(struct http_parser *hp,
   rb_str_buf_cat(hp->cont, vptr, end + 1);
 }
 
+#ifndef HAVE_RB_FSTRING
+static VALUE my_fstring(VALUE str)
+{
+  OBJ_FREEZE(str);
+
+  return str;
+}
+#define rb_fstring(str) my_fstring((str))
+#endif /* !HAVE_RB_FSTRING */
+
 static void write_value(VALUE hdr, struct http_parser *hp,
                         const char *buffer, const char *p)
 {
@@ -273,7 +283,7 @@ static void write_value(VALUE hdr, struct http_parser *hp,
 
     if (NIL_P(e)) {
       /* new value, freeze it since it speeds up MRI slightly */
-      OBJ_FREEZE(f);
+      f = rb_fstring(f);
 
       if (hclass == rb_cHash)
         rb_hash_aset(hdr, f, v);
-- 
1.8.4



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] use rb_fstring from Ruby 2.1.0dev if available
  2013-10-12  3:18 [PATCH] use rb_fstring from Ruby 2.1.0dev if available Eric Wong
@ 2013-10-12  6:59 ` Eric Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2013-10-12  6:59 UTC (permalink / raw)
  To: kcar

Eric Wong <normalperson@yhbt.net> wrote:
> This should be safe after r43210 from ruby trunk

Ugh, that was a horrible commit message.

This uses the frozen string cache in Ruby 2.1.0 if available.  The
frozen string cache implements the:

	"literal string"f

syntax found in Ruby 2.1.0 (this Ruby syntax is not set-in-stone, but
the idea of the frozen string cache seems to be popular in ruby-core
right now and unlikely to go away).

Strings in the frozen string cache benefit from best-effort
deduplication, but can still be GC-ed (unlike Symbols).  Obviously they
are strings, too, so they're usable for Rack headers.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-10-12  6:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-12  3:18 [PATCH] use rb_fstring from Ruby 2.1.0dev if available Eric Wong
2013-10-12  6:59 ` Eric Wong

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/kcar.git/

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).